php - 拉维尔 : OrderBy the paginated Eloquent relationship result

标签 php pagination laravel-5.2

我的应用程序使用 Laravel 5.2

我有两个模型:链接和关联。它们之间的关系是:Link hasMany Affiliates。 当我想要一个链接的关联公司时,我想对结果进行分页,这按预期工作,但我也想按结果排序。我该怎么做?

这是我当前的代码:

$affiliates = $link->affiliates->paginate(50, ['*'], 'p')->orderBy('created_at', 'desc')->orderBy('visitor_ip', 'desc');

谢谢!

最佳答案

像这样的东西应该可以工作:

$affiliates = Affiliate::where('link_id', $id)->orderBy('created_at', 'desc')->orderBy('visitor_ip', 'desc')->paginate(50, ['*'], 'p');

关于php - 拉维尔 : OrderBy the paginated Eloquent relationship result,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35745155/

相关文章:

php - 显示来自数据库的图像

java - SOLR 会占用服务器大量内存吗?

javascript - 使 Javascript 中的分页可扩展(对于大量的数据库结果)

android - 如何将分页请求发送到firebase以实现无限滚动的recyclerview

php - 如何统计一个目录下的文件个数?

php - laravel图像干预是压缩用户上传图像的好方法吗?

angularjs - AngularJS 中如何进行分页?

php - Laravel 中的 whereHas 查询

php - 如何在 Laravel 5.2 中存储多选值

php - 从数据库表中填充选择下拉列表