0

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?

Steve
  • 1,553
  • 2
  • 20
  • 29
masterhunter
  • 551
  • 2
  • 10
  • 29
  • select (case status when status= 'Pending' then 1 when status= 'Rejected' then 2 when status= 'Approved' then 3 end) as new_order from table order by new_order asc – JYoThI May 16 '17 at 05:19

1 Answers1

2

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

Community
  • 1
  • 1
Kuru
  • 738
  • 5
  • 18