Pagination
php
public function pagination(): Pagination
{
return Pagination::make(default: 20, max: 100);
}or, on a query, ->pagination(default: 20, max: 100).
The request may then pass page and per_page:
GET /users?page=3&per_page=50Both are validated with the rest of the request (page from 1, per_page from 1 to the maximum), and paginate() or simplePaginate() without an explicit page size use them. The pagination links keep the query string.
Parameter names
php
Pagination::make(pageParameter: 'p', perPageParameter: 'pageSize')reads the page and the page size under other names, for an API that already uses them. The links and the error messages follow.
Limiting the page number
php
Pagination::make(maxPage: 500)caps page, for listings where deep offsets are expensive. A page whose offset ((page - 1) × per_page) would not fit an integer is always rejected.
Lookups by key
find(), findOrFail(), findMany() and the like apply the filters, fields and includes of the request, but not the order of its sorts, which means nothing to them.