laravel order by desc Query Builder

Today, We want to share with you laravel order by desc Query Builder.In this post we will show you Eloquent latest(), add orderby id on top of order, hear for laravel raw query with parameters we will give you demo and example for implement.In this post, we will learn about Using OrderBy for multiple columns in Laravel 4/5/6/7 with an example.

laravel order by desc Query Builder

There are the Following The simple About Adding Multiple OrderBy clause in Laravel Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel Quick Tip: orderByRaw() with ORDERBY, so the Database: Query Builder is used for this example is following below.

Eloquent sort query Laravel

By DESC order

$doctors = DB::table('doctors')->orderBy('doctor_name', 'desc')->get();

By ASC order

$doctors = DB::table('doctors')->orderBy('doctor_name', 'asc')->get();

Using OrderBy for multiple columns in Laravel

multiple columns using Laravel

Doctor::orderBy('doctor_name', 'DESC')
->orderBy('hospital_name', 'ASC')

SQL Query

SELECT * FROM `doctors` ORDER BY `doctor_name` DESC , `hospital_name` ASC , `address` ASC;

pass it as an array

Doctor::orderBy(array('doctor_name'=>'desc', 'hospital_name'=>'asc'))

Using OrderByRaw will also produce the same result.

Doctor::orderBy(array('doctor_name'=>'desc', 'hospital_name'=>'asc'))

Web Programming Tutorials Example with Demo

Read :


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Using OrderBy for multiple columns in Laravel 4/5/6/7.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Related FAQ

Here are some more FAQ related to this Article:

  1.   laravel db Raw SQL Queries select insert and Update
  2.   Laravel Advance Database Query Builder
  3.   Eloquent Right Join Queries in Laravel Example
  4.   Laravel Framework version Types
  5.   MySQL Remove special characters from database
  6.   laravel join Multiple Tables using Model Example
  7.   Laravel 6 try catch Database Transaction
  8.   laravel Views share Variable multiple to controller
  9.   Fetch Last week month year records in MySQL
  10.   PHP Laravel Eloquent join with subquery