我的数据库中有:
tops
表posts
表tops_has_posts
表.
当我从tops
表中检索一个顶部时,我也会检索与该顶部相关的posts
。
但是如果我想按照特定顺序检索这些帖子呢?
因此,我在我的枢轴表tops_has_posts
中添加了一个range
字段,并尝试使用Eloquent通过结果进行排序,但不起作用。
我尝试过以下代码:
$top->articles()->whereHas('articles', function($q) {
$q->orderBy('range', 'ASC');
})->get()->toArray();
还有这个:
$top->articles()->orderBy('range', 'ASC')->get()->toArray();
两者都是拼命的尝试。
提前感谢。