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.

READ :  Laravel 5.8 Get Last Inserted ID

How to use order By clause in Laravel?

Example 1:

Movie::where(['status'=>'active'])->orderBy('m_name')->get()

Example 2: many order by clause in Laravel Example

Movie::where(['status'=>'active'])->orderBy('m_name')->orderBy('total_reviews','DESC')->orderBy('created_at')->get()

Example 3: Using order by twice

Movie::orderBy('m_name', 'DESC')
    ->orderBy('total_reviews', 'ASC')
    ->get();

Example 4: Using raw order by:

Movie::orderByRaw("m_name DESC, total_reviews ASC")->get();

Order by using multiple columns and manually array field in Laravel 6

using DB Object

$movies_list = DB::table('movies')
    ->select('movies.*')
    ->orderBy('movie_id', 'asc')
    ->orderBy('sub_movie_id', 'asc')
    ->get();

dd($movies_list);

Example:Laravel 6 order by multiple columns

$movies_list = DB::table('movies')
    ->select('movies.*')
    ->orderByRaw(DB::raw("FIELD(status, 'Pending', 'Approved', 'Rejected')"))
    ->get();

dd($movies_list);    

solution:laravel collection sort by multiple columns

$movies_list = DB::table('movies')
    ->select('movies.*')
    ->orderByRaw(DB::raw("FIELD(sub_movie_id, 8, 9, 4, 6) DESC"))
    ->get();

dd($movies_list);

Web Programming Tutorials Example with Demo

Read :

READ :  Laravel 5.8 Check if file exists or not

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.