jaman
answered Apr 27 '23 00:00
In Laravel 5.2, you can use the orderBy() method to set the order of the results returned by the all() method or any other method that returns a collection. Here's an example:
$users = User::orderBy('name', 'asc')->get();
In this example, we are using the orderBy() method to order the users by the name column in ascending order. We then use the get() method to retrieve all of the users in the order specified by the orderBy() method.
Note that the all() method still exists in Laravel 5.2, but it returns a Collection instance instead of a model query builder instance. If you want to use the query builder to set the order of the results, you should use the get() method instead of the all() method.