laravel
laravel copied to clipboard
Add ability to set limit without pagination
Please add a way to return a specified number of results without pagination, i.e. set a limit
in the SQL query without performing a count query or returning paging information. That would save significant time and data when pagination is not needed. Thanks.
So I'd been thinking I could implement this via a class that could be returned from the paginator()
method on a schema. However, the query builders only call that if the page
query parameter has a value (or if there is default pagination).
Thinking about this, I don't think I need to add any additional capability, because there is already the indexQuery()
hook on the schema, that is called for the fetch resources request. Documented here:
https://laraveljsonapi.io/docs/1.0/requests/authorization.html#index-filtering
So you can do:
public function indexQuery(?Request $request, Builder $query): Builder
{
return $query->limit(100);
}
And for to-many relationships you can use the relatableQuery()
method as documented here: https://laraveljsonapi.io/docs/1.0/requests/authorization.html#relatable-filtering
@hayespdx I think that solves the issue, can you confirm?
Closing this as no further follow up on it. The above comment provides details of how to do this with the current implementation.