Skip to content

Conversation

@josephistired
Copy link
Contributor

Description

Fixes #2441 - Updates the results API controller to properly handle pagination with the spatie/laravel-json-api-paginate package.

Changes

  • Updated validation from per_page to page.size to match JSON:API standard
  • Changed jsonPaginate() call to explicitly set max (500) and default (25) values
  • This allows the API to properly respect the page[size] query parameter up to 500 results

Testing

  • ?page[size]=500 now returns 500 results (previously capped at 30)
  • ?page[size]=25 returns 25 results
  • ?page[size]=x returns whatever x is, as long as under 500.
  • No parameter returns 25 results (default)
  • Values above 500 are rejected by validation

@alexjustesen
Copy link
Owner

@josephistired thanks for the PR, can you fix the lint errors that cropped up?

Also looks like the default is set by the config which we'd want to use instead of hard coding the max limit. Fell free to publish the package config and update the default there.

If you want to go a step further you can make this configurable by referencing an environment variable. Just change:

// config/json-api-paginate.php

/*
 * The maximum number of results that will be returned
 * when using the JSON API paginator.
 */
'max_results' => 30,

to...

// config/json-api-paginate.php

/*
 * The maximum number of results that will be returned
 * when using the JSON API paginator.
 */
'max_results' => env('API_MAX_RESULTS', 30),

Copy link
Owner

@alexjustesen alexjustesen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above for changes ☝️

@josephistired
Copy link
Contributor Author

@alexjustesen Thanks for the feedback. I added the config file that uses max_results => env('API_MAX_RESULTS', 500), so the limit defaults to 500 unless the user sets their own environment value. I also made sure the default page size is 25 when page[size] isn’t provided in the query. The validation now checks against either the user’s configured limit or the default 500. Also, linted the code.. sorry.

If you're good with these changes, let me know. I’ll also open a request to update the docs to include the new ENV setting and the updated query parameter.

@alexjustesen
Copy link
Owner

alexjustesen commented Nov 26, 2025

@josephistired go ahead and open a PR for the docs too. You don't need to update the API just the env variable list.

Edit: also linting failed again, make sure to add those EOF lines and if you're using an agent add that to your guidelines as a best practice.

@josephistired
Copy link
Contributor Author

josephistired commented Nov 26, 2025

@alexjustesen Just opened a PR for the docs. Confused about the linting, as GitHub states the test passed? Will add those EOF lines right now.

Edit: Added EOF line to config file. All files I changed have EOF lines.

@alexjustesen alexjustesen merged commit 86ea672 into alexjustesen:main Nov 26, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] per_page parameter capped at 30 despite controller validation allowing up to 500

2 participants