@mstnorris something like this?
$post = Post::with('replies', function($query){
return $query->paginate(12); // or whatever
})->find($id);
I have implemented pagination on my forum index page which lists groups of 12 posts along with details about each one including number of replies etc.
I want to be able to paginate the replies when I view a certain post.
What is the Eloquent (or query) that will allow me to achieve this? So far I have this but it throws an error.
public function show($id)
{
$post = Post::with('replies')->paginate(12)->find($id);
return view('posts.show', compact('post'));
}
@mstnorris It does exactly the same as long as we talk about the db:
$post = Post::with('replies')->find($id); // 2 queries
$post = Post::find($id); // 1st query
$replies = $post->replies()->paginate(12); // 2nd query
Please or to participate in this conversation.