When I do this, it doesn't do what I expect - get the "paginated" result of the related comments per post. Below, it only returns the comments of the first post.
Post::with(['comments' => function($query) {
$query->offset(0)->limit(10);
}])->get()
Result:
[
{
...
"comments" : [
[Comment], [Comment], [Comment] # <-- Only this post has comments.
]
},
{
...
"comments" : [
] # <-- Other posts do not have comments. =(
}
]
I aim to have each array item above to have a max of 10 comments in "paginated" manner using offset and limit on with().
Is it possible to do this in Laravel?