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

gurvindersingh's avatar

I want to sort order by date and order by priority simultaneously.

I have two columns created_at and priority I want to show recently added records first. like I have 5 records on 27-Jan-2019. I want to show these 5 records using order by priority in asc.

0 likes
3 replies
shez1983's avatar

you can have two order by clauses in your query? whats ur current q looking like?

Snapey's avatar
Snapey
Best Answer
Level 122

Chain on the additional order. You need the date first and then the priority.

Model::latest()->orderBy('priority','DESC')->get();
1 like
ahsan's avatar

agree with @snapey

but if you are looking for Ascending Order

it would be

Model::latest()->orderBy('priority','ASC')->get();
3 likes

Please or to participate in this conversation.