How to sort a Laravel query builder result by multiple columns? | Laravel Point

 

How to sort a Laravel query builder result by multiple columns?

You can sort a Laravel query builder result by multiple columns by passing an array of columns to the orderBy method. Here is an example:

       $users = DB::table('users')
                ->orderBy(['name' => 'asc', 'email' => 'desc'])
                ->get();

In this example, the result will be sorted first by the name column in ascending order and then by the email column in descending order.

Previous Post Next Post

Contact Form