bool or an Illuminate Auth Response.authorizeResource() method on both resource and query request classes has
changed to bool|Response (where response is the Illuminate Auth response). If you are manually calling this method
and relying on the return value being a boolean, this change is breaking. However, the vast majority of applications
should be able to upgrade without any changes.self link in related resource responses,
and remove related link that should not exist. This has been incorrect for some time, but is definitely what
the spec defines here.8.2.ulid() method to the ID field class.8.1.laravel-json-api/cursor-pagination package, you now need to passed the schema's id field
to the paginator's make() method. I.e. use CursorPagination::make($this->id())Accept header for a "delete" resource request. Previously there was no checking of the Accept media
type, so anything could be sent. This is incorrect as the JSON:API specification shows the Accept header as
application/vnd.api+json for delete resource requests.MultiPaginator that allows a schema to offer multiple different pagination strategies.fieldspagefilterfields query parameter, e.g. /api/v1/employees?fields[employees]=.canEagerLoad() method.WhereNull and WhereNotNull filters.404 Not Found scenario).laravel-json-api/validation dependency.JsonApiException class now has a context() method. Laravel's exception handler uses this to add log context
when the exception is logged. This means logging of JSON:API exceptions will now include the HTTP status code and the
JSON:API errors.406 Not Acceptable and 415 Unsupported Media Type messages to the following two new exception
classes:
Exceptions\HttpNotAcceptableExceptionExceptions\HttpUnsupportedMediaTypeExceptionAccept header with the media type
application/json is rejected with a 406 Not Acceptable response. Previously this media type worked, which is
incorrect as the JSON:API specification requires the media type application/vnd.api+json.null for a to-one relationship update."0".toOne() or toMany() methods on the
resource request class.Number field can now be configured to
accept numeric strings by calling the acceptStrings() method on the field.readonly as a keyword. It was therefore necessary to rename the following interface
and trait:
LaravelJsonApi\Eloquent\Contracts\ReadOnly is now IsReadOnly.LaravelJsonApi\Eloquent\Fields\Concerns\ReadOnly is now IsReadOnly.Server class in an application:
LaravelJsonApi\Core\Support\AppResolver.$container property has been removed, and the $app property is now private. To access the
current application instance in your server class, use $this->app() instead.model() and modelOrFail() methods
on the ResourceQuery request class have been changed from public to protected. These were not documented for use
on this query class, and were only intended to be used publicly on the ResourceRequest class. Although technically
breaking, this change is unlikely to affect the vast majority of applications which should not be using the method.LaravelJsonApi\Laravel\LaravelJsonApi::defaultResource() method. This should be set in a service
provider's register() method.JsonApiResource class now has a
protected serializeRelation method that can be used to override the default serialization of relationships if
needed.self
routes will now include any non-standard links set on the resource relationship in the top-level links member.JsonApiResource now correctly handles conditional
fields when iterating over relationships to find a specific relation.self
route now handles a relationship not existing if it is hidden. Previously an exception was thrown when attempting to
merge relationship links into the document.self and related relationship links.WhereHas and WhereDoesntHave filters.
Previously these were not iterating over the filters from the correct resource schema - they were iterating over the
filters from the schema to which the relationship belonged. They now correctly iterate over the filters from the
schema for the resource that is on the inverse side of the relationship.Has, WhereHas, WhereDoesntHave. Refer to
the filter documentation for details.canCount() method on a relationship. Refer to
the Countable relationships chapter in the
documentation for more details.1.x release cycle. If you are already using our cursor implementation, you can migrate in two easy steps:
composer require laravel-json-api/cursor-paginationLaravelJsonApi\Eloquent\Pagination\CursorPagination to LaravelJsonApi\CursorPagination\CursorPagination.showRelated() and showRelationship() methods. Previously both these controller
actions were authorized via the single showRelationship() method. Adding the new showRelated method means
developers can now implement separate authorization logic for these two actions if desired. Our default implementation
remains unchanged - both are authorized using the view<RelationshipName> method on the relevant policy.isCreatingOrUpdating() helper method to determine whether the request is to create or
updated a resource.meta member.extractUsing() callback. This receives the model, column name and value. This is useful if the developer
needs to control the serialization of a few fields on their schema. However, the recommendation is to use a resource
class for complete control over the serialization of a model to a JSON:API resource.8.30. This change was required to use the $stopOnFirstFailure property on Laravel's
FormRequest class.LaravelJsonApi\Spec\UnexpectedDocumentException which was thrown if there was a failure when decoding
request JSON content before parsing it for compliance with the JSON:API specification. A JsonApiException will now
be thrown instead.201 Created response.sortables() method.$defaultSort property.jsonapi:sort-field to create a custom sort field class.PostQuery and PostCollectionQuery) via the $defaultIncludePaths property. These include
paths are used if the client does not provide any include paths.fill() method on Eloquent fields has
been updated to receive all the validated data as its third argument. This change was made to allow fields to work out
the value to fill into the model based on other JSON:API field values. If you have written any custom fields, you will
need to update the fill() method on your field class.belongsTo, hasOne, hasOneThrough and morphOne relationships that
have a withDefault() method. As part of this change, the mustExist() method was added to the Fillable interface.
If you have written any custom fields, you will need to add this method to your field class - it should return true
if the attribute needs to be filled after the primary model has been persisted.include, sort and
withCount query parameters.withCount query parameter. For Eloquent
resources, this allows a client to request the relationship count for the primary data's relationships. Refer to
documentation for implementation details.ID field needs to implement the LaravelJsonApi\Contracts\Schema\IdEncoder interface for this to work.laravel-json-api/hashids package and using the HashId field instead of the standard Eloquent ID field. Refer to
documentation for details.laravel-json-api/non-eloquent package. Refer to documentation for implementation details.Core\Reponses\RelatedResponse class for returning the result for a related resources endpoint. For
example, the /api/v1/posts/1/comments endpoint. Previously the DataResponse class was used. While this class can
still be used, the new RelatedResponse class merges relationship meta into the top-level meta member of the
response document. For to-many relationships that are countable, this will mean the top-level meta member will
contain the count of the relationship.--non-eloquent option to generate a schema for a non-Eloquent
resource.LaravelJsonApi::registerQuery(), LaravelJsonApi::registerCollectionQuery() and
LaravelJsonApi::registerRequest() methods must now be used to register custom HTTP request classes for specified
resource types. Previously methods could be called on the RequestResolver classes, but these have now been removed.MorphToMany relation field can now be used to add
polymorphic to-many relations to a schema. Refer to documentation for details.serving() method.RequestResolver::registerRequest(),
RequestResolver::registerQuery() and RequestResolver::registerCollectionQuery() static methods.jsonapi:authorizer generator command.indexQuery and relatableQuery methods. These allow filtering for authorization
purposes when a list of resources is being retrieved. For instance, it could filter those queries so that only models
belonging to the authenticated user are returned.searching, reading, saving, creating,
updating, deleting, readingRelated<Name>, reading<Name>, updating<Name>, attaching<Name> and
detaching<Name>.Server
classes.MetaResponse class that can be used
when returning meta-only responses. In addition, response classes have been updated to add a withServer method. This
can be used to specify the named server the response should use to encode the JSON:API document. This has to be used
when returning responses from routes that have not run the JSON:API middleware (i.e. there is no default server
available via the service container).resources, relationships and actions callbacks as the second function argument.Schema::isSingular() method.tags but the client sends posts, the
request will be rejected with an error message that posts are not supported.index and store methods on the
authorizer contract now receive the model class as their second argument. This is useful for authorizers that are used
for multiple resource types.using() must be replaced
with withRequest(). This change was made to make it clearer that the request class can be passed into query
builders.Relation::type() method must now be used when
setting the inverse resource type for the relation.fields query parameter to field set
value objects.Content-Type
header.Relation::inverseType() method is deprecated and will be removed in 1.0-stable. Use Relation::type()
instead.actions() helper method when registering resources. See the PR for examples.JsonApiController now has the Laravel AuthorizesRequests, DispatchesJobs and ValidatesRequests traits
applied.when() and mergeWhen() method
should be used to add conditional relationships.$with property.existingAttributes() and existingRelationships() methods on the resource request class has been removed.
If you need to modify the existing values before the client values are merged, implement the withExisting()
method instead. This receives the model and its JSON representation (as an array).mustValidate() method must now be called on a schema relationship field. (Previously this was on the
resource relation.) By default, belongs-to and morph-to relations will be included when extracting existing
values; all other relations will not. Use the mustValidate() or notValidated() method on the schema relation
to alter whether a relation is included in the extracted values.hidden and serializeUsing methods to customise the serialization of models by the schema.meta() method.ArrayList and ArrayHash have been added, to distinguish between PHP zero-indexed arrays that
serialize to JSON arrays (ArrayList) and PHP associative arrays that serialize to JSON objects (ArrayHash). The
distinction is required because an empty array list can be serialized to [] in JSON whereas an empty associative
array must be serialized to null in JSON.attributes(), relationships(),
meta(), and links() methods have been changed 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. When upgrading, you will need to either
delete resource classes (as they are now optional), or update the method signatures on any classes you are retaining.v1 server after
adding this package to their Laravel application.Arr schema field has been removed - use the new ArrayList or ArrayHash
fields instead.uri method on resource and relationship routes has been removed:
$uriType property).withUriFieldName method).Initial release.
How can I help you explore Laravel packages today?