publicoms/laravel-custom-paginator is a Laravel package for paginate based on last item, not pages..
It currently has 0 GitHub stars and 2.206 downloads on Packagist.
Install it with composer require publicoms/laravel-custom-paginator.
Discover more Laravel packages by publicoms
or browse all Laravel packages to compare alternatives.
Last updated
Paginate based on last item, not page.
composer require publicoms/laravel-custom-paginator
Add the following trait to your Models.
use \publicoms\ItemPaginator\ItemPaginatorTrait;
Add the following provider to config/app.php
\publicoms\ItemPaginator\ItemPaginatorServiceProvider::class,
This package is based off simplePaginate and will take the same parameters.
$users = new User();
$paginated = $users->itemPaginate();
dd($paginated);
The last parameter is the field that will be used to paginate by, defaults to id.
itemPaginate($perPage = null, $columns = ['*'], $pageName = 'from', $from = 0, $field = null)
If you want to decend your sorting you'll want to use itemPaginateDesc instead of itemPaginate. The first page will add an extra query to find the last item.
array:6 [
"limit" => 2
"next_page_url" => "http://localhost?from=190"
"from" => 100
"to" => 190
"data" => array:2 [
0 => array:8 [
"id" => 100
"name" => "test"
"email" => "[email protected]"
"password" => "test"
"remember_token" => null
"created_at" => "2016-08-02 18:13:19"
"updated_at" => "2016-08-02 18:13:19"
"deleted_at" => null
]
1 => array:8 [
"id" => 190
"name" => "test2"
"email" => "[email protected]"
"password" => "test"
"remember_token" => null
"created_at" => "2016-08-02 18:13:19"
"updated_at" => "2016-08-02 18:13:19"
"deleted_at" => null
]
]
]
I've only tested this with sqlite and mysql (see tests) so it may not work in every situation. Please report any you find.