Adding Multiple Order By clause in Laravel

2024-03-04 04:15:19 Sushant Laravel

How to use order By clause in Laravel?

Order by is used to sort sql results by column names. In this example we will see how to add multiple orderby clause in Laravel.

Let take an example we have a users table and we want to sort results by name of user, then here is query to do that in Laravel.


The above Eloquent query return all user those status is active in sorted ascending order by name. To sort in descending order use orderBy('name','DESC').

Similarly you can add as many order by clause in Laravel. Here is an example.


This post is submitted by one of our members. You may submit a new post here.

Related Tricks