stepanenko3 / laravel-pagination
为 Laravel 优秀的分页生成器
v1.0.3
2024-03-14 11:53 UTC
Requires
- php: ^8.0
- laravel/framework: ^10.0|^11.0
Requires (Dev)
- phpstan/phpstan: ^1.10
- tightenco/duster: ^2.7
README
描述
为 Laravel 优秀的分页生成器
示例
1, 2, 3, 4, 5, ..., 20
1, ..., 12, 13, 14, ..., 20
1, ..., 16, 17, 18, 19, 20
要求
php: >=8.0
laravel/framework: ^9.0
安装
# Install the package
composer require stepanenko3/laravel-pagination
使用
在 app\Builders\BaseBuilder.php
中创建自己的数据库构建器
use Stepanenko3\LaravelPagination\Pagination; use Illuminate\Database\Eloquent\Builder; class BaseBuilder extends Builder { public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null) { $page = $page ?: Pagination::resolveCurrentPage($pageName); $perPage = $perPage ?: $this->model->getPerPage(); $results = ($total = $this->toBase()->getCountForPagination()) ? $this->forPage($page, $perPage)->get($columns) : $this->model->newCollection(); return new Pagination($results, $total, $perPage, $page, [ 'path' => Pagination::resolveCurrentPath(), 'pageName' => $pageName, ]); } }
或者不使用数据库构建器
new Pagination( $items, $total, $perPage, $currentPage, );
鸣谢
贡献
感谢您考虑为这个包做出贡献!请创建一个带有详细说明您所提议更改的 pull request。
许可证
此包是开源软件,根据 MIT 许可协议 许可。