Today, We want to share with you Laravel Multiple Order By Columns.In this post we will show you wordpress plugin require another plugin, hear for Adding Multiple Order By Clause using Laravel we will give you demo and example for implement.In this post, we will learn about How to Use Order By for Multiple Columns in Laravel 6? with an example.
Laravel Multiple Order By Columns
There are the Following The simple About laravel collection sort by multiple columns Full Information With Example and source code.
As I will cover this Post with live Working example to develop Laravel 6 order by multiple columns, so the Using OrderBy for multiple columns in Laravel 6 is used for this example is following below.
How to use order By clause in Laravel?
Example 1:
[php]
Movie::where([‘status’=>’active’])->orderBy(‘m_name’)->get()
[/php]
Example 2: many order by clause in Laravel Example
[php]
Movie::where([‘status’=>’active’])->orderBy(‘m_name’)->orderBy(‘total_reviews’,’DESC’)->orderBy(‘created_at’)->get()
[/php]
Example 3: Using order by twice
[php]
Movie::orderBy(‘m_name’, ‘DESC’)
->orderBy(‘total_reviews’, ‘ASC’)
->get();
[/php]
Example 4: Using raw order by:
[php]
Movie::orderByRaw(“m_name DESC, total_reviews ASC”)->get();
[/php]
Order by using multiple columns and manually array field in Laravel 6
using DB Object
[php]
$movies_list = DB::table(‘movies’)
->select(‘movies.*’)
->orderBy(‘movie_id’, ‘asc’)
->orderBy(‘sub_movie_id’, ‘asc’)
->get();
dd($movies_list);
[/php]
Example:Laravel 6 order by multiple columns
[php]
$movies_list = DB::table(‘movies’)
->select(‘movies.*’)
->orderByRaw(DB::raw(“FIELD(status, ‘Pending’, ‘Approved’, ‘Rejected’)”))
->get();
dd($movies_list);
[/php]
solution:laravel collection sort by multiple columns
[php]
$movies_list = DB::table(‘movies’)
->select(‘movies.*’)
->orderByRaw(DB::raw(“FIELD(sub_movie_id, 8, 9, 4, 6) DESC”))
->get();
dd($movies_list);
[/php]
Web Programming Tutorials Example with Demo
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about Multiple orderBy on Laravel 6 Query.
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.