订购者正在为此工作...
$posts = PostClass::where('thread_id',1)->orderBy('id','desc')->paginate(20);
但按此顺序不起作用。
$thread = ThreadClass::find(1);
$posts = $thread->posts()->orderBy('id','desc')->paginate(20);
Laravel版本:5.5
答案 0 :(得分:2)
要允许orderBy在相关帖子上发生,您可以将dynamic属性作为一种关联方法来访问。
$posts = $thread->posts()->orderBy('posts.id','desc')->paginate(20);