Pagination
Pagination bounds query results and supports navigation.
What it is
Pagination bounds query results and supports navigation.
When to use it
Use for lists that can grow.
Syntax
Order::where("user_id", $user->id)->orderBy("id")->paginate(20);Example
$orders = $request->user()->orders()->orderBy("id")->paginate(20);
return OrderResource::collection($orders);
// Keyset approach for large changing datasets:
$orders = $request->user()->orders()->orderBy("id")->cursorPaginate(20);Common mistakes
Use a stable unique ordering; cap client-controlled page sizes; cursor pagination has ordering constraints.