Today, We want to share with you order by multiple columns(fields) laravel query builder.In this post we will show you Adding Multiple Order By clause in Laravel 5/6/7, hear for laravel query builder order by two columns we will give you demo and example for implement.In this post, we will learn about Using OrderBy for multiple columns in Laravel with an example.
order by multiple columns(fields) laravel query builder
There are the Following The simple About laravel 5.6 order by multiple columns, Full Information With Example and source code.
As I will cover this Post with live Working example to develop Orderby the difference of two columns in Laravel, so the laravel query builder orderby two columns is used for this example is following below.
Order by using multiple columns and manually array field in Laravel?
Multiple Columns OrderBy
$patients = DB::table('patients') ->select('patients.*') ->orderBy('docator_id', 'asc') ->orderBy('sub_site_id', 'asc') ->get(); dump($patients);
order by like pending, approved and rejected status
$patients = DB::table('patients') ->select('patients.*') ->orderByRaw(DB::raw("FIELD(status, 'Pending', 'Approved', 'Rejected')")) ->get(); dump($patients);
give ‘ASC’ or ‘DESC’ order in query
$patients = DB::table('patients') ->select('patients.*') ->orderByRaw(DB::raw("FIELD(sub_site_id, 4, 5, 7, 9) DESC")) ->get(); dump($patients);
I hope you get an idea about Sorting | laravel-query-builder.
I would like to have feedback on my infinityknow.com 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.