spatie/laravel-fast-paginate
A fast limit/offset paginator for Laravel. The fastPaginate method selects only primary keys first so late pages stay fast, then fetches full rows for that page. Same signature and paginator as Laravel's paginate, so no other code changes.
Adopt when all of these hold:
WHERE and ORDER BY columns are indexed, ideally with the primary key appended, so the inner key-only query can be satisfied from the index.groupBy, having, union, distinct, or exotic select aliases that break the two-step fetch.Look elsewhere when:
cursorPaginate() is O(1) on deep pages and already in the framework. If the UI tolerates "next/previous" instead of "page N," this package is the wrong answer.withCount usage are outside its sweet spot and will silently degrade.To executives: This is a low-cost, MIT-licensed fix for slow back-office list pages — deep pages currently force the database to read every preceding row, and this package cuts that per-page cost substantially. It's a one-line change on affected screens, requires no API or client changes, and needs no vendor contract. Treat it as a tactical optimization with a defined exit path, not a platform bet.
To engineering: It implements a deferred join — a key-only indexed query for the page's IDs, then a primary-key lookup for full rows. We should (1) benchmark p95 on deep pages against production-shaped data, (2) confirm the inner query is index-covered, (3) check for groupBy/union/distinct in affected queries, and (4) keep the change isolated per-endpoint so reverting is a one-line diff. The real long-term answer for high-traffic endpoints remains cursor pagination; this unblocks the page-number UX in the meantime. Given the package's adoption profile, assume we may need to vendor the implementation — the method is small enough that this is a contained risk.
How can I help you explore Laravel packages today?