Using OrderBy for all() in Laravel

When you want all the results from a call to be in the order you can use OrderBy .

$results = Project::all();

Here project is the model. Let's see how to use OrderBy on this.

$results = Project::orderBy('name')->get();

If you want the result in ascending or descending order you can change it as given below.

$results = Project::orderBy('created_at', 'desc')->get();