instead of doing with get() do like this
$post = Post::where('slug', $slug)->firstOrFail()->minipost()->orderBy('created_at', 'desc')->paginate(5);
and have a look to the docs as well http://laravel.com/docs/5.1/pagination
Hello guys, I am having a hard time solving pagination problem.
Are there a way to paginate a collection? or how can i paginate a post while ordering it by created at?
Post::where('slug', $slug)->firstOrFail()->minipost()->orderBy('created_at', 'desc')->get();
This is the code that i use to retrieve the latest minipost for the post. But 1 post can have more then 15 minipost.. I want to paginate this so that in the first page i can see the latest 5 minipost and second page another 5 minipost
How can i solve this?
$post = Post::where('slug', $slug)->firstOrFail()->minipost()->orderBy('created_at', 'desc')->get();
$post->paginate(5); // not working Call to undefined method
instead of doing with get() do like this
$post = Post::where('slug', $slug)->firstOrFail()->minipost()->orderBy('created_at', 'desc')->paginate(5);
and have a look to the docs as well http://laravel.com/docs/5.1/pagination
Please or to participate in this conversation.