publicoms / laravel-custom-paginator
基于最后一项进行分页,而不是基于页面。
dev-master
2021-03-10 14:10 UTC
Requires
- php: ^7.0|^8.0
- symfony/http-foundation: ~2.7|~3.0|~4.0|~5.0
- symfony/http-kernel: ~2.7|~3.0|~4.0|~5.0
Requires (Dev)
- phpunit/phpunit: ^6|^7|^8|^9
- squizlabs/php_codesniffer: ^3.5
This package is not auto-updated.
Last update: 2024-09-20 01:27:53 UTC
README
基于最后一项进行分页,而不是页面。
安装
composer require publicoms/laravel-custom-paginator
将以下特性添加到您的模型中。
use \publicoms\ItemPaginator\ItemPaginatorTrait;
将以下提供者添加到 config/app.php
\publicoms\ItemPaginator\ItemPaginatorServiceProvider::class,
使用
此包基于 simplePaginate,并使用相同的参数。
$users = new User(); $paginated = $users->itemPaginate(); dd($paginated);
最后一个参数是用来分页的字段,默认为 id
。
itemPaginate($perPage = null, $columns = ['*'], $pageName = 'from', $from = 0, $field = null)
ORDER BY DESC
如果您想降序排序,应使用 itemPaginateDesc
而不是 itemPaginate
。第一页将添加一个额外的查询来查找最后一项。
示例输出
array:6 [ "limit" => 2 "next_page_url" => "https://?from=190" "from" => 100 "to" => 190 "data" => array:2 [ 0 => array:8 [ "id" => 100 "name" => "test" "email" => "test@test.com" "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" => "test2@test.com" "password" => "test" "remember_token" => null "created_at" => "2016-08-02 18:13:19" "updated_at" => "2016-08-02 18:13:19" "deleted_at" => null ] ] ]
免责声明
只按递增的ID排序。
我仅在 sqlite
和 mysql
上进行了测试(见测试),因此可能不在所有情况下都适用。请报告您发现的情况。