How To Order Query Results in Laravel Eloquent
In a previous part of this series, you learned how to obtain database records using the all() method from within an Eloquent model, sorting the resulting collection with the sortDesc() method. In this guide, you’ll learn how to use the orderBy() method to sort results in the database query itself, which offers more flexibility and performance to order query results at the database level.