[英]How to sort a collection by reputation and creation date
Assuming I want to sort a list of users by reputation: 假设我想按声誉对用户列表进行排序:
By doing $query->get()->sortByDesc('reputation')
, I receive the following results: 通过$query->get()->sortByDesc('reputation')
,我收到以下结果:
How can I sort the collection to receive results similar to the first example? 如何对集合进行排序以接收与第一个示例类似的结果? In other words, if users have 0 reputation, how can I change the sorting method to creation date by descending order? 换句话说,如果用户的声誉为0,如何按降序将排序方法更改为创建日期?
在查询中链接两个orderBy()
方法:
->orderBy('created_at', 'desc')->orderBy('reputation', 'desc')->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.