senty
senty

Reputation: 12857

Collection Query Builder - orderBy multiple values

In my eloquent model, I have a location row. It holds 5 potential answers such as:

I want to perform an orderBy and want them to be listed as this order. Is there a way to achieve it with orderBy? Something like:

People::orderBy('location', ['Hotel, 'Library', 'Accommodation']);

What is the best way to achieve this?

Upvotes: 2

Views: 521

Answers (1)

MyLibary
MyLibary

Reputation: 1771

So, you can achieve that by using:

People::orderByRaw("FIELD(location , 'Hotel, 'Library', 'Accommodation') ASC") 

Of course, you may choose ASC or DESC.

Upvotes: 4

Related Questions