askedio / laravel-item-paginate
该软件包已被废弃,不再维护。未建议替代软件包。
基于最后一条项目分页,而不是页面。
1.2.0
2016-08-29 22:25 UTC
Requires
- php: >=5.5.9
- laravel/framework: 5.*
Requires (Dev)
- codacy/coverage: dev-master
- laravel/laravel: 5.*
- phpunit/phpunit: 4.*
This package is not auto-updated.
Last update: 2020-01-19 14:52:03 UTC
README
基于最后一条项目分页,而不是页面。
安装
composer require askedio/laravel-item-paginate
将以下特性添加到您的模型中。
use \Askedio\ItemPaginator\ItemPaginatorTrait;
将以下提供者添加到 config/app.php
\Askedio\ItemPaginator\ItemPaginatorServiceProvider::class,
使用
此软件包基于simplePaginate,将采用相同的参数。
$users = new User(); $paginated = $users->itemPaginate(); dd($paginated);
最后一个参数是用于分页的字段,默认为 id
。
itemPaginate($perPage = null, $columns = ['*'], $pageName = 'from', $from = 0, $field = null)
按降序排序
如果您想按降序排序,应使用 itemPaginateDesc
而不是 itemPaginate
。第一页将添加一个额外的查询以查找最后一条项目。
示例输出
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" => "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
上进行了测试(请参阅测试),因此它可能不会在每种情况下都正常工作。请报告您发现的所有情况。