laravel eloquent sort by code example
Example 1: order By Asc in laravbel
->orderBy('id', 'DESC');
Example 2: laravel order by
$users = DB::table('users')
-> orderBy('name', 'desc')
-> get();
Example 3: eloquent model sort by ascending order
$posts = Post::orderBy('id', 'DESC')->get();
Example 4: laravel sort collection
$collection = collect([5, 3, 1, 2, 4]);
$sorted = $collection->sortDesc();
$sorted->values()->all();
Example 5: get all sort by laravel
$results = Project::orderBy('name')->get();