Integrations
Laravel's native JSON:API
How this package compares with, and works alongside, Laravel's own JSON:API resources.
Laravel (12.46+, 13) ships Illuminate\Http\Resources\JsonApi\JsonApiResource, a lean implementation of the
specification that suits many APIs. This package stays independent of it and interoperates with it.
What each one covers
| Laravel's native | This package | |
|---|---|---|
id as a string, "data": null, primary data out of included | yes | yes |
| Attributes resolved after the sparse fieldset | yes | yes |
| Relationships that are not included | left out | linkage loaded in batch, or left out (relationship.linkage) |
| Typed values: nullable, date format, decimal precision, enum | no | yes |
Definition of a resource, validation of include and fields | no | yes |
Links and meta per relationship, whenIncluded(), can(), filters | no | yes |
| Resources that are not Eloquent models | no | yes |
| Public contract for the tooling (OpenAPI) | no | yes |
| Error documents, content negotiation | no | yes |
| API revisions | no | yes |
Relating native resources
A relationship may relate native resources:
protected function toRelationships(Request $request): iterable
{
return [
'author' => $this->one(NativeUserResource::class),
'tags' => $this->many(NativeTagResource::class),
];
}
- Their linkage is rendered and loaded in batch as any other;
links(),meta()andidentifierMeta()receive the native resource. A native resource is guessed like any other (#[UseResource], then the naming convention). - Included, they are rendered as leaves by their own
resolve(), with theirfields[type]: their relationships are never rendered, nothing is loaded nor included under them, and theIncludesrule rejectsinclude=author.posts. - Their fields are unknown without a model: the
Fieldsrule accepts those of their type as they are. - A polymorphic relationship (
morph()) cannot render native resources.
A native JsonApiRequest is read like any request.