JCC Eloquent ORM
Pagination
Introduction
JCC-Eloquent provides pagination at both model and builder level.
Pagination reads the current HTTP request via the global request() helper — you do not pass req as the first argument. Page number comes from request().query.page (default 1). Link URLs use request().protocol, host, and path.
Both methods return data + pagination metadata.
Model pagination
Model.paginate(perPage?, page?):
This returns:
datameta(current_page,per_page,total,total_pages,has_more,links)links(first,last)
Query builder pagination
Builder pagination works on filtered queries:
Use this when pagination must respect custom constraints.
Simple pagination
simplePaginate uses offset pagination without running a COUNT(*) query — faster for large tables when you don't need a total count:
Response shape:
No total or total_pages — just whether there is a next page.
Cursor pagination
cursorPaginate implements keyset (cursor-based) pagination — stable and O(1) for any page depth, regardless of table size:
Response shape:
Pass the next page by forwarding ?cursor=<token> from meta.next_cursor.
When to use cursor vs offset pagination:
paginate | simplePaginate | cursorPaginate | |
|---|---|---|---|
Runs COUNT(*) | yes | no | no |
| Supports total pages | yes | no | no |
| Stable under inserts | no | no | yes |
| Random page access | yes | no | no |
Manual offset/limit alternative
For full manual control:
Notes
pageis clamped to a minimum of1.perPageis cast to number internally.- Pagination link generation uses request protocol/host/path.
Summary
- Use
paginate(perPage)for standard pagination with total counts and page links. - Use
simplePaginate(perPage)for large tables where you don't need a total count. - Use
cursorPaginate(perPage)for high-performance, stable pagination on large or frequently-updated tables. - Pagination uses the global
request()helper for page number and link generation — call it inside a route handler or middleware context. - Use
offset+limitonly for fully custom paging flows.