在this section中,我读到有关嵌套的渴望加载的信息
但此情况未在其中显示。
我可以代替
$books = App\Book::with(['author.posts', 'author.comments', 'author.rating'])->get();
这样吗?
$books = App\Book::with(['author' => function ($query) {
$query->with(['posts', 'comments', 'rating'])
}])->get();
我可以提出这样的请求吗?
$books = App\Book::with(['author' => function ($query) {
$query->with([
'posts' => function ($query) {
$query->with('author');
},
'comments' => function ($query) {
$query->with(['author' => function ($query) {
$query->where('created_at', '>=', now()->subDays(5));
}]);
}
]);
}])->get();