Skip to content

[Feature] Make resource classes optional #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 2, 2021

Conversation

lindyhopchris
Copy link
Contributor

Resource classes are now optional. If one does not exist, the implementation falls-back to serializing resource using the schema. The serialization can be customised on the Eloquent schema using the hidden() and serializeUsing() methods.

The change also updates the JsonApiResource method signatures for the attributes, relationships, meta, and links methods so that they receive the HTTP request as the first (and only) parameter. This brings the implementation in line with Laravel's Eloquent resources, which receive the request to their toArray() method. The slight difference is our implementation allows the request to be null - this is to cover encoding resources outside of HTTP requests, e.g. queued broadcasting.

This is a breaking change. Any existing Resource classes will either need to be deleted, or if keeping them the method signatures for the attributes, relationships, links and meta methods need to be updated to add the request as the first parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant