我有一个一对多的关系,为我的“公告”设置了许多“评论”。Laravel Pass对帖子的评论
目前,当我的用户负荷高达应用程序页面,我把它送30个最近宣布像这样:
Route::get('/app', function() {
$posts = Announcement::take(30)->orderBy('id', 'desc')->get();
return View::make('app')->with([
//posts
'posts' => $posts,
//orders
'orders' => $orders
]);
}
当我回声出使用foreach循环通过$帖子在叶片上的公告对象,我还想在各自的帖子中回复每篇文章的评论。
是否可以将帖子的评论作为实际帖子对象的一部分传递给该帖子?例如,这将是很好,如果我能做到这一点:
@foreach ($posts as $post)
//echo out the post
{{$post->content}}
//echo out the comments relating to this post
{{$post->comments}}
@endforeach