Exemple :
$users = User::where('votes', '>', 100)->paginate(15);
You can find more results http://laravel.com/docs/5.1/pagination#paginating-eloquent-results
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I need to paginate an Eloquent collection (so after DB call). But from what I've read doing Paginator::make() doesn't exists anymore. I'm a little confused of how I should do it ? Examples would be nice.
My aim is to still do $items->appends(Request::only(['type', 'size']))->render() in my view and be able to keep the inputs in the pagination links and display them as I would have if the pagination was done on the query with ->paginate().
Thanks for your help
You can create your own pagination object after it
$users = User::where('votes', '>', 100)->get();
$page = Input::get('page', 1); // Get the ?page=1 from the url
$perPage = 15; // Number of items per page
$offset = ($page * $perPage) - $perPage;
return new LengthAwarePaginator(
array_slice($users->toArray(), $offset, $perPage, true), // Only grab the items we need
count($users), // Total items
$perPage, // Items per page
$page, // Current page
['path' => $request->url(), 'query' => $request->query()] // We need this so we can keep all old query parameters from the url
);
Please or to participate in this conversation.