Skip to content

Pagination

crisp-oquent parses Laravel's API Resource paginated payload out of the box.

Basic

ts
const page = await User.crispy()
  .filter('active', true)
  .paginate(2, 25);

page.items;          // User[]
page.currentPage;    // 2
page.perPage;        // 25
page.total;          // 137
page.lastPage;       // 6
page.hasMorePages(); // true
page.links.next;     // 'https://api.example.com/users?page=3'

Expected backend payload

json
{
  "data": [{ "id": 1, "name": "..." }, { "id": 2, "name": "..." }],
  "meta": {
    "current_page": 2,
    "per_page": 25,
    "total": 137,
    "last_page": 6,
    "from": 26,
    "to": 50
  },
  "links": {
    "first": "https://api.example.com/users?page=1",
    "last": "https://api.example.com/users?page=6",
    "prev": "https://api.example.com/users?page=1",
    "next": "https://api.example.com/users?page=3"
  }
}

This matches Laravel's default JsonResource::collection($paginator) shape.

Iterating all pages

For when you really do need everything:

ts
const everyone = await User.crispy().filter('active', true).all();

.all() walks pages until hasMorePages() returns false. By default it caps at 100 pages — pass maxPages to override:

ts
await User.crispy().all(500);   // safety cap at 500 pages

WARNING

Use .all() with care. Paginated APIs exist for a reason.