Level 47
Create the paginator after you sort the results. Try this:
$posts = Posts::all()->sortBy(function ($post) {
// custom sort here
})->paginate(3);
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I want to sort results with custom function and want to paginate the result.
I try this. EG :
$posts = Post::paginate(3)->sortBy(function ($post) {
// custom sort here
});
It 's work . But when i show pagination in views with $posts->render();. It said "Method render does not exist".
How to sort with custom function and paginate properly. Is there any better ways to do it?
Please or to participate in this conversation.