laminas/laminas-paginator
Laminas Paginator provides flexible pagination for PHP apps, with adapters for arrays, iterators, and database results. Generate page ranges and navigation data, and integrate with Laminas MVC or use standalone for paged listings.
Start by installing via Composer: composer require laminas/laminas-paginator. Then, create a paginator by wrapping any traversable data source (array, Doctrine Query, custom iterator) in a Laminas\Paginator\Paginator instance and specifying an adapter (e.g., Laminas\Paginator\Adapter\ArrayAdapter, Laminas\Paginator\Adapter\DbSelect). Configure the adapter with your data source and call $paginator->setCurrentPageNumber($page) and $paginator->setItemCountPerPage($count). For immediate output, render using a view helper like $this->paginator($paginator, 'scrolling_style') in a Blade or Twig view (via integration with Laravel's view layer), or iterate over $paginator directly in Blade.
Use adapters to abstract pagination logic: for Eloquent, wrap Model::where(...)->cursor() in Laminas\Paginator\Adapter\Callback or use the Laminas\Paginator\Adapter\LaravelEloquent community adapter (or build a simple custom one using count() and skip()->take()). Integrate with Laravel’s Request by injecting request()->get('page', 1) into setCurrentPageNumber(). Combine with Laravel’s pagination links via render() returning HTML compatible with Bootstrap/Tailwind if adapted correctly. Use caching adapters (e.g., Laminas\Paginator\Adapter\NullAdapter for mocks or custom caching wrappers) for expensive queries—cache the total count and slices. For APIs, return JSON with toArray() and embed metadata (total, current, per_page) manually or via a transformer.
Adapter choice is critical: DbSelect requires explicit adapter setup (not auto-inferred), and ArrayAdapter loads all items into memory—avoid for large datasets. The pageRange setting in view helpers affects link rendering (e.g., number of page links shown); configure it in config or helper options. Pagination state is not persisted across requests unless you manually store it (e.g., in session or query params); always initialize with request context. Debug with $paginator->getPages() to inspect metadata (current, total, next/prev pages). If using with Eloquent, prefer simplePaginate() or custom adapters that use skip()->take() instead of count()-heavy methods for performance. Custom adapters must implement getItems($offset, $itemCountPerPage) returning an array and count() returning an int. Note: As of 2025, laminas-paginator has minimal Laravel-specific integration—patch view helpers or create a service provider to bind adapters cleanly to Laravel’s container.
How can I help you explore Laravel packages today?