Download the PHP package sammyt/paginate-collection without Composer
On this page you can find all versions of the php package sammyt/paginate-collection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sammyt/paginate-collection
More information about sammyt/paginate-collection
Files in sammyt/paginate-collection
Package paginate-collection
Short Description Allows laravel users to paginate a collection via a global helper method. Currently laravel only allows for native query builder pagination.
License MIT
Informations about the package paginate-collection
Laravel Paginate Collection
Description:
Allows laravel users to paginate a collection via a global helper method. Currently laravel only allows for native query builder pagination.
Usage:
As a simple inline example I created a fresh Laravel project using:
laravel new MyProject
In MyProject
:
- Set up an
.env
file which connects to a local database. - Run the out-of-the-box migrations making sure the
users
table is created. - Use
tinker
to create some test users in theusers
table or create them manually in your DB
To test you can call this method globally and pass in your collection. Other method parameters are optional. Accepted parameters include:
$collection
=> Required$perPage
=> Default is 15 but also accepts anint
$currentPage
=> Default is null but also accepts anint
$options
=> Any additional options you wish to pass
Below is an example use case of how to use the paginate_collection
global helper method.
Follow steps 1-3 above and then create a route in web.php
which has a callback function
which will allow you to return a collection for testing
Output
As you can see it uses the LengthAwarePaginator
behind the scenes and your collection is now paginated.