Reputation: 12857
In my eloquent model, I have a location row. It holds 5 potential answers such as:
Hotel
Accommodation
Library
rest of the values
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
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