Eloquent sortBy - Specify asc or desc

Laravel 5

https://laravel.com/docs/5.8/collections#method-sortby

Laravel 4

https://laravel.com/api/4.2/Illuminate/Database/Eloquent/Collection.html#method_sortBy

Usage

$collection->sortBy('field', [], true); // true for descending

To sort by ASC: Laravel Docs - sortBy()

$collection->sortBy('field');

To sort by DESC: Laravel Docs - sortByDesc()

$collection->sortByDesc('field');


In 4.2, the second parameter needs to be an int, SORT_REGULAR is default

https://laravel.com/api/4.2/Illuminate/Database/Eloquent/Collection.html#method_sortBy

$collection->sortBy('field', SORT_REGULAR, true); //true for descending