desmart / pagination
Laravel pagination on steroids
Installs: 9 070
Dependents: 1
Suggesters: 0
Security: 0
Stars: 40
Watchers: 15
Forks: 7
Open Issues: 1
pkg:composer/desmart/pagination
Requires
- php: >=5.4.0
- illuminate/pagination: 4.2.*
- illuminate/routing: 4.2.*
- illuminate/support: 4.2.*
Requires (Dev)
- mockery/mockery: 0.8.*
This package is auto-updated.
Last update: 2022-02-01 12:25:23 UTC
README
This package is an extension for Laravel4 pagination module.
It provides new functionalities:
- route based url generator
- helpers for template render
Installation
To composer.json add: "desmart/pagination": "1.2.*" and then run composer update desmart/pagination.
In app/config/app.php replace line 'Illuminate\Pagination\PaginationServiceProvider', with 'DeSmart\Pagination\PaginationServiceProvider',.
Compatibilty
This package should not break compatibility with Laravel pagination module.
Laravel 4.1
To use desmart/pagination with Laravel 4.1 switch to version 1.1.*.
Laravel 4.0
To use desmart/pagination with Laravel 4.0 switch to version 1.0.*.
Method overview
General usage
withQuery()- bind query parameters to url generator (by default query parameters are included). Works only for url generating from routes.withoutQuery()- don't bind query parametersroute($route[, array $parameters])- use given route for generating url to pages (it can be route name, or instance ofIlluminate\Routing\Route)useCurrentRoute()- use current (active) route for url generating
For templates
pagesProximity($proximity)- set pages proximitygetPagesRange()- get list of pages to show in template (includes proximity)canShowFirstPage()- check if can show first page (returnsTRUEwhen first page is not in list generated bygetPagesRange())canShowLastPage()- check if can show last page (returnsTRUEwhen last page is not in list generated bygetPagesRange())
Example usage
In controller
// example route (app/routes.php) Route::get('/products/{page}.html', array('as' => 'products.list', 'uses' => '')); // use the current route $list = Product::paginate(10) ->useCurrentRoute() ->pagesProximity(3); // use custom route $list = Product::paginate(10) ->route('products.list') ->pagesProximity(3);
In view
// app/view/products/list.blade.php @foreach ($list as $item) {{-- show item --}} @endforeach {{ $list->links('products.paginator') }} // app/view/products/paginator.blade.php @if ($paginator->getLastPage() > 1) @foreach ($paginator->getPagesRange() as $page) {{ $page }} @endforeach @endif
License
This package is open-sourced software licensed under the MIT license