Ad
Laravel Model Eager Loading And Ordering
I'm new to Laravel and thought it be cool to purchase the Codehappy ebook by Dayle Rees.
I just finished the blog tutorial and thought a bit on how he retrieved the posts from the Post model. Coming from a .net (ASP.NET MVC) background I think it will be important to order the posts while eager loading the author.
He eager loads the model like this.
$posts = Post::with('author')->get();
My question is where can you use the "order_by" clause? the order_by itself works when I use:
$posts = Post::order_by('id', 'desc')->get();
Regards RaVen
Ad
Answer
I manage to solve it by:
$posts = Post::with('author')->order_by('id', 'desc')->get();
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad