我的应用程序使用 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/