Skip to content

Releases: laravel-json-api/laravel

Allow zero as a resource id

01 Apr 19:53
Compare
Choose a tag to compare

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

20 Feb 18:18
Compare
Choose a tag to compare

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() or toMany() methods on the resource request class.
  • #113 The Eloquent Number field can now be configured to accept numeric strings by calling the acceptStrings() method on the field.

Laravel 9 and PHP 8.1

12 Feb 17:53
Compare
Choose a tag to compare

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 now IsReadOnly.
    • LaravelJsonApi\Eloquent\Fields\Concerns\ReadOnly is now IsReadOnly.
  • 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.
  • BREAKING #110 The 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.

Improvements and bug fixes

03 Jan 16:49
Compare
Choose a tag to compare

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's register() method.
  • #127 The JsonApiResource class now has a protected serializeRelation 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-level links 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 and related relationship links.

Fix `WhereHas` filter bug

08 Dec 18:35
Compare
Choose a tag to compare

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 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.

Initial stable release

31 Jul 19:55
Compare
Choose a tag to compare

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:
    1. Install the new package: composer require laravel-json-api/cursor-pagination
    2. In any schemas using the cursor pagination, change the import statement
      from LaravelJsonApi\Eloquent\Pagination\CursorPagination to LaravelJsonApi\CursorPagination\CursorPagination.

Authorizer updates, debug exceptions and more improvements

10 Jul 10:48
Compare
Choose a tag to compare

Added

  • The authorizer now has separate 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.
  • 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's FormRequest 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. A JsonApiException 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

02 Jun 13:01
Compare
Choose a tag to compare
Pagination links fix Pre-release
Pre-release

Fixed

  • #76 Pagination links will now be correctly added to related resources and relationship identifiers responses.

Sort fields and default include paths

26 Apr 13:44
Compare
Choose a tag to compare
Pre-release

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 and PostCollectionQuery) 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

20 Apr 13:29
Compare
Choose a tag to compare

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 the fill() 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 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.
  • #58 Schema model classes can now be a parent class or an interface.

Fixed

  • #69 Fixed the parsing of empty include, sort and withCount query parameters.