laravel
laravel copied to clipboard
Cursor pagination does not support hashids
Having setup and followed the docs to enable hashids, I've discovered that when using hashids with Cursor Pagination, the meta page info uses the ids from the DB column.

_Trying without validating page query. I get "the selected page.after is invalid with proper validation _


Thanks for reporting this - it is indeed a bug. There's already a PR in the cursor pagination package relating to this, and my comment on it here explains that I need to amend that package so the ID field is injected into the cursor paginator.
I'll prioritise this for a fix, probably in the next week or two.
@othneildrew I think I've solved this but it would be good if you could give it a go.
To give it a go, run the following:
composer require "laravel-json-api/cursor-pagination:dev-feature/id-decoding"
To use in your schema, you would just need to do the following:
public function pagination(): CursorPagination
{
return CursorPagination::make($this->id());
}
@lindyhopchris My apologies that this took me soon long to review. But I'm happy to report that it works wonderfully, thanks so much for fixing this!
The only missing piece I think is the validation of page params now.
For example, something like this would no longer pass validation checks:
'page.after' => 'filled|string|exists:lessons,id',
'page.before' => 'filled|string|exists:lessons,id',
Yeah good point, I need to add some Rule objects that cover validating JSON:API identifiers in query parameters (JSON:API identifiers in JSON:API documents are already validated automatically).
Closing in favour of #237 - that documents that I need to add things to make validating resource IDs a lot easier.