集合查询生成器 - orderBy 多个值

Collection Query Builder - orderBy multiple values

在我的 eloquent 模型中,我有一个位置行。它包含 5 个可能的答案,例如:

我想执行 orderBy 并希望将它们列为此订单。有没有办法用 orderBy 来实现?类似于:

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

实现此目标的最佳方法是什么?

因此,您可以通过以下方式实现:

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

当然,您可以选择 ASC 或 DESC。