更新时间:2023-01-19 19:13:25
如果您试图获取 topic
的 reply
,则需要急于加载.另外,如果您与 user
有关系,谁也急于加载它.
If you are trying to get topic
's replies
you need to eager load. Also if you have relation with user
who replied eager load it as well.
使用 latest()
方法获取最新回复.
Use latest()
method for getting latest replies.
仅对于名称
和 date
,我们具有 select()
.
public function show($id)
{
$topics = $topic->with('replies' => function($query) {
$query->with('user')->select('name', 'created_at')->latest();
});
$theme = Theme::with('topics')->find($id);
return view('themes.theme', compact('topics', 'theme'));
}