acadea / collection-paginator
Laravel Package to paginate any collection
Fund package maintenance!
acadea
Requires
- php: ^7.3
- illuminate/contracts: ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.3
- vimeo/psalm: ^3.11
This package is auto-updated.
Last update: 2024-11-14 15:16:55 UTC
README
A helper package to paginate Laravel collections.
About
Learn the idea behind this package:
- Read on my Medium blog: How to Paginate Collection
- or watch it on Youtube
Follow us on Youtube: Acadea.io
Installation
You can install the package via composer:
composer require acadea/collection-paginator
Usage
$collection = collect([1,2,3,4,5,6,7,8]); $pageSize = 4; $paginated = \Acadea\CollectionPaginator\CollectionPaginator::paginate($collection, $pageSize); // .. // in resource controller, returning as an api response return new \Illuminate\Http\JsonResponse($paginated);
Expects:
{ "current_page": 1, "data": [ 1, 2, 3, 4 ], "first_page_url": "http://localhost:8000/api/fruits?page=1", "from": 1, "last_page": 2, "last_page_url": "http://localhost:8000/api/fruits?page=2", "links": [ { "url": null, "label": "Previous", "active": false }, { "url": "http://localhost:8000/api/fruits?page=1", "label": 1, "active": true }, { "url": "http://localhost:8000/api/fruits?page=2", "label": 2, "active": false }, { "url": "http://localhost:8000/api/fruits?page=2", "label": "Next", "active": false } ], "next_page_url": "http://localhost:8000/api/fruits?page=2", "path": "http://localhost:8000/api/fruits", "per_page": 4, "prev_page_url": null, "to": 4, "total": 8 }
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.