Reputation: 559
How to get all data and orderBy specific word. For example I have column name status. In the status is store for "Approved", "Pending","Rejected".
How can i sort the data like show all status "Pending" with descending order?
Upvotes: 0
Views: 1557
Reputation: 738
This might work:
$data= DB::table('table_name')
->orderby(DB::raw('case when status= "Pending" then 1 when status= "Rejected" then 2 when status= "Approved" then 3 end'))
->get();
References
Question in stackoverflow
Laravel Documentation
Upvotes: 2