Optional Resources
Pre-release
Pre-release
·
281 commits
to develop
since this release
Added
- #1 Resource classes are now optional. If one is not defined, the implementation falls-back to using the Eloquent schema to serialize a model. Eloquent schema fields now have new
hidden
andserializeUsing
methods to customise the serialization of models by the schema. - Resource classes now support using conditional attributes in their
meta()
method. - New field classes
ArrayList
andArrayHash
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 tonull
in JSON.
Changed
- BREAKING The JsonApiResource method signatures for the
attributes()
,relationships()
,meta()
, andlinks()
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 theirtoArray()
method. The slight difference is our implementation allows the request to benull
- 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.
Fixed
- #3 Example server registration in the published configuration file prevented developer from creating a
v1
server after adding this package to their Laravel application. - Package discovery for sub-packages that have service providers now works correctly.
Removed
- BREAKING The
Arr
schema field has been removed - use the newArrayList
orArrayHash
fields instead. - BREAKING The
uri
method on resource and relationship routes has been removed:- The resource type URI can now be set on the resource's schema (using the
$uriType
property). - Relationship URIs are now set on the schema field for the relationship (via the
withUriFieldName
method).
- The resource type URI can now be set on the resource's schema (using the