-
Notifications
You must be signed in to change notification settings - Fork 43
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
always including data for every relationship #127
Comments
Hi @robinstraub . I don't think you can skip the creation of the resource/schema classes, but maybe this section in the documentation can help with the include paths. |
Thanks for your reply, I ended up creating a trait for overloading the relationships() method of the JsonApiResource classes, which let me update the default content of the relationships:
which let me have fairly simple JsonApiResource classes, given I don't need to customize the resource content :
Aside from the hassle of creating the resource classes manually, this works fine for my use case. |
To better support this use case, 1.1 (not yet tagged) adds the following: The protected function serializeRelation(SerializableRelation $relation): JsonApiRelation
{
return parent::serializeRelation($relation)->alwaysShowData()->withoutLinks();
} Also, if you wanted to make this change across the whole of your API (i.e. for every resource), you can now change the default class that is used for for the JSON:API resource. In your service provider: use LaravelJsonApi\Laravel\LaravelJsonApi;
public function register(): void
{
LaravelJsonApi::defaultResource(MyResourceClass::class);
} |
Closing as will be in the |
Hi,
I am building an API and am used to produce resources that always have the data segment of their relationships. I used to use this on my frontend using this former package version. I came across this section of the official documentation explaining how to provide it using the resource classes.
Is there a way to always provide the data, without having to write resource classes for every schema and specifying the alwaysIncludeData() on every relationship ?
The text was updated successfully, but these errors were encountered: