Mar 26, 2017
5
Level 4
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!
Level 1
2 likes
Please or to participate in this conversation.