hillcow's avatar

Paginate blog example from "Laravel 5.4 from Scratch series"

Hi there,

I followed the Laravel 5.4 from Scratch series and am currently trying to implement pagination into the blog example.

It's easy to get pagination for the homepage:

Post::latest()->filter(request(['month', 'year']))->simplePaginate(5);

Problem: paginate() or simplePaginate() cannot be called like this:

public function index(Tag $tag){
$posts = $tag->posts->paginate(5);
return view('posts.index', compact('posts'));
}

So when I visit /posts/tags/{tag}, it tells me method paginate() doesn't exist. How am I supposed to paginate the results in that case, so that I can still hand over the Eloquent model of Post (which I need to display all the details)?

Thank you very much!

0 likes
5 replies
hillcow's avatar

@RobertWillis Thanks, but that doesn't answer my question at all and I chose your answer as best answer by accident :D Did you read my question?

jlrdw's avatar

@hillcow I don't know if it's possible to un-mark, so you may want to start a new post.

Please or to participate in this conversation.