Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

md_imran's avatar

Order by Status (pending, approved, rejected)

Hello Genius,

I can get the list with order by date or anything with asc or desc. But I need to fetch the data which 'status' = 'pending' first then others status.

How can I do that?

TIA

0 likes
3 replies
MichalOravec's avatar
Level 75

I think this could work

->orderByRaw('status = "pending" desc')->orderBy('created_at')
idbmannaf's avatar

->orderBy(DB::raw('case when status= "pending" then 1 when status= "approved" then 2 when status= "rejected" then 3 end'))

Please or to participate in this conversation.