stepanenko3 / laravel-pagination
Great pagination generator for Laravel
Installs: 73 405
Dependents: 3
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 1
Open Issues: 1
Requires
- php: ^8.0
- laravel/framework: ^10.0|^11.0
Requires (Dev)
- phpstan/phpstan: ^1.10
- tightenco/duster: ^2.7
This package is auto-updated.
Last update: 2024-12-16 19:36:51 UTC
README
Description
Great pagination generator for Laravel
Examples
1, 2, 3, 4, 5, ..., 20
1, ..., 12, 13, 14, ..., 20
1, ..., 16, 17, 18, 19, 20
Requirements
php: >=8.0
laravel/framework: ^9.0
Installation
# Install the package
composer require stepanenko3/laravel-pagination
Usage
Create your own database builder in 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, ]); } }
Or use without database builder
new Pagination( $items, $total, $perPage, $currentPage, );
Credits
Contributing
Thank you for considering contributing to this package! Please create a pull request with your contributions with detailed explanation of the changes you are proposing.
License
This package is open-sourced software licensed under the MIT license.