Reputation: 725
I have 2 tables: posts and comments. Post and Comment has one-to-many relationship.
I have managed to evaluate paginations of posts and comments with following code:
$posts = Post::with(array(
'comments' => function($c) {
$c->paginate(5);
}))
->paginate(10);
First line below gives the links of $posts, but the second doesn't.
{{ $posts->links() }}
{{ $post->comments->links() }}
It gives the following error:
Call to undefined method Illuminate\Database\Eloquent\Collection::links()
How can I evaluate the links of comments of each post?
Note: {{ $post->comments }} gives the comments of the specified post.
Upvotes: 0
Views: 191
Reputation: 12293
I think you have two things to figure out here:
I think we need to know what you want to have as a result of this query. In what scenario are you paginating both posts and its child comments at the same time?
Upvotes: 0
Reputation: 11
Try to use
{{ $posts->comments->link }}
if it's not working, try:
{{ $posts->comments()->link }}
Make sure you've set up the relationship correctly first.
Upvotes: 1