I\'m stuck on a simple task. I just need to order results coming from this call
$results = Project::all();
Where Project
is
In addition, just to buttress the former answers, it could be sorted as well either in descending desc
or ascending asc
orders by adding either as the second parameter.
$results = Project::orderBy('created_at', 'desc')->get();
Try this:
$categories = Category::all()->sortByDesc("created_at");
Check out the sortBy
method for Eloquent: http://laravel.com/docs/eloquent
Laravel 5.4 added orderByDesc() methods to query builder:
$results = Project::orderByDesc('name')->get();