Releases: laravel-json-api/laravel
Releases · laravel-json-api/laravel
Allow zero as a resource id
Upgrading
composer require laravel-json-api/laravel --no-update
composer up laravel-json-api/*
Changelog
Fixed
- #178 Allow a resource id that is
"0"
.
Request and number field improvements
Upgrading
composer require laravel-json-api/laravel --no-update
composer up laravel-json-api/*
Changelog
Added
- #110 For requests that modify a relationship, it is now possible to get the model or models referenced in the request JSON using the
toOne()
ortoMany()
methods on the resource request class. - #113 The Eloquent
Number
field can now be configured to accept numeric strings by calling theacceptStrings()
method on the field.
Laravel 9 and PHP 8.1
Upgrading
Refer to the upgrade guide on our website.
Changelog
Added
- This package now supports Laravel 9.
- This package now supports PHP 8.1.
Changed
- BREAKING PHP 8.1 introduces
readonly
as a keyword. It was therefore necessary to rename the following interface and trait:LaravelJsonApi\Eloquent\Contracts\ReadOnly
is nowIsReadOnly
.LaravelJsonApi\Eloquent\Fields\Concerns\ReadOnly
is nowIsReadOnly
.
- Return types have been added to all internal methods in all child packages, to remove deprecation messages in PHP 8.1
- #83 Amended container bindings to ensure package works with Laravel Octane. Most of these changes should have no impact on consuming applications. However, the following changes could potentially be breaking to the JSON:API
Server
class in an application:- The type-hint of the first constructor argument has changed to
LaravelJsonApi\Core\Support\AppResolver
. - The deprecated
$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.
- The type-hint of the first constructor argument has changed to
- BREAKING #110 The
model()
andmodelOrFail()
methods on theResourceQuery
request class have been changed frompublic
toprotected
. These were not documented for use on this query class, and were only intended to be used publicly on theResourceRequest
class. Although technically breaking, this change is unlikely to affect the vast majority of applications which should not be using the method.
Improvements and bug fixes
Upgrading
composer require laravel-json-api/laravel --no-update
composer up laravel-json-api/*
Added
- The default JSON:API resource class can now be changed via the
LaravelJsonApi\Laravel\LaravelJsonApi::defaultResource()
method. This should be set in a service provider'sregister()
method. - #127 The
JsonApiResource
class now has a protectedserializeRelation
method that can be used to override the default serialization of relationships if needed. - #111 Relationship documents returned by relationship
self
routes will now include any non-standard links set on the resource relationship in the top-levellinks
member.
Fixed
- #147 Related relationship response now correctly merge the relationship links into the top-level document links member.
- #130 The
JsonApiResource
now correctly handles conditional fields when iterating over relationships to find a specific relation. - #105 The JSON:API document returned by a relationship
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. - #111 Relationship documents now handle a relationship that does not have one or both of the
self
andrelated
relationship links.
Fix `WhereHas` filter bug
Upgrading
composer up laravel-json-api/*
Changed
- The maximum PHP version is now 8.0. PHP 8.1 is not supported because it introduces a breaking change. The next major version of this package will add support for PHP 8.1.
Fixed
- #139 Fix the
WhereHas
andWhereDoesntHave
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.
Initial stable release
Finally, our initial stable release. Yes there's more features to work on, but this package is definitely production ready - so here at last is a stable release!
Upgrade Instructions
composer require laravel-json-api/laravel --no-update
composer require laravel-json-api/testing --dev --no-update
composer up laravel-json-api/* cloudcreativity/json-api-testing
Added
- New relationship filter classes:
Has
,WhereHas
,WhereDoesntHave
. Refer to the filter documentation for details.
Changed
- BREAKING: Countable Relationships. This feature is now turned off by default. Although included in the 1.0 release, this feature is not considered production-ready. This is because we plan to make breaking changes to it, which will change how the client requests countable relationships. As such, this feature is considered highly-experimental and developers must opt-in to it by calling the
canCount()
method on a relationship. Refer to the Countable relationships chapter in the documentation for more details. - BREAKING: Cursor Pagination. Laravel now has its own cursor pagination feature. We have therefore moved our implementation into its own package: laravel-json-api/cursor-pagination This change has been made because it makes sense for the in-built cursor pagination implementation to use Laravel's cursor pagination implementation rather than our own custom one. Support for Laravel's cursor pagination will be added during the
1.x
release cycle. If you are already using our cursor implementation, you can migrate in two easy steps:- Install the new package:
composer require laravel-json-api/cursor-pagination
- In any schemas using the cursor pagination, change the import statement
fromLaravelJsonApi\Eloquent\Pagination\CursorPagination
toLaravelJsonApi\CursorPagination\CursorPagination
.
- Install the new package:
Authorizer updates, debug exceptions and more improvements
Added
- The authorizer now has separate
showRelated()
andshowRelationship()
methods. Previously both these controller actions were authorized via the singleshowRelationship()
method. Adding the newshowRelated
method means developers can now implement separate authorization logic for these two actions if desired. Our default implementation remains unchanged - both are authorized using theview<RelationshipName>
method on the relevant policy. - The request class now has a
isCreatingOrUpdating()
helper method to determine whether the request is to create or updated a resource. - Add stop on first failure to all validators in the resource request class.
- #85 When running an application with debug mode turned on, the default JSON:API error object for an exception will now contain detailed exception information, including the stack trace, in the object's
meta
member. - #103 Can now fully customise attribute serialization to JSON using the
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.
Changed
- Minimum Laravel version is now
8.30
. This change was required to use the$stopOnFirstFailure
property on Laravel'sFormRequest
class. - Schema classes no longer automatically sort their fields by name when iterating over them. This change was made to give the developer full control over the order of fields (particularly as this order affects the order in which fields are listed when serialized to a JSON:API resource). Developers can list fields in name order if that is the preferred order.
- Removed the
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. AJsonApiException
will now be thrown instead.
Fixed
- #101 Ensure controller create action always returns a response that will result in a
201 Created
response. - #102 The attach and detach to-many relationship controller actions now correctly resolve the collection query class using the relation's inverse resource type. Previously they were incorrectly using the primary resource type to resolve the query class.
Pagination links fix
Fixed
- #76 Pagination links will now be correctly added to related resources and relationship identifiers responses.
Sort fields and default include paths
Added
- #14 Additional sort parameters can now be added to Eloquent schemas. Previously only sortable attributes were supported. These new classes are added to schemas in the
sortables()
method. Refer to the new Sorting chapter in the documentation. - Eloquent schemas now support a default sort order via the
$defaultSort
property. - New generator command
jsonapi:sort-field
to create a custom sort field class. - #74 Developers can now add default include paths to the query request classes (e.g.
PostQuery
andPostCollectionQuery
) via the$defaultIncludePaths
property. These include paths are used if the client does not provide any include paths.
Attributes from related models and various improvements
Added
- #65 BREAKING The
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 thefill()
method on your field class. - BREAKING Eloquent attributes now support serializing and filling column values on related objects. This is primarily intended for use with the Eloquent
belongsTo
,hasOne
,hasOneThrough
andmorphOne
relationships that have awithDefault()
method. As part of this change, themustExist()
method was added to theFillable
interface. If you have written any custom fields, you will need to add this method to your field class - it should returntrue
if the attribute needs to be filled after the primary model has been persisted. - #58 Schema model classes can now be a parent class or an interface.
Fixed
- #69 Fixed the parsing of empty
include
,sort
andwithCount
query parameters.