All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning and this changelog format.
- [#70] Url prefix was not being passed to encoder leading to invalid links in JSON API documents.
- An encoder can now be obtained for a named API via the JSON API service
encodermethod. - New Blade directives for outputting encoded JSON API data in templates:
@jsonapi($apiName)for configuring the encoder to use. Optionally takes$host,$optionsand$deptharguments.@encode($data)for encoding data. Optionally takes$includePathsand$fieldSetsarguments.
- Added a broadcasting helper trait (
Broadcasting\BroadcastsData) to aid broadcasting of JSON API data.
- Changes to import statements for resource object and standard object interfaces, to reflect changes in the
cloudcreativity/json-apipackage.
- Removed the validator error factory interface from this library as the one provided by
cloudcreativity/json-apihas the additional methods on it. - The deprecated
isActivemethod on the JSON API service (available via the facade) has been removed.
- Generator for API config -
php artisan make:json-api <name> - All routes registered now have route names.
- Support for packages providing resources into an API via a
ResourceProviderclass. Note that this is currently experimental.
- Route registration has been refactored so that only the JSON API routes that are required for a specific resource type are registered.
- Config is now defined on a per-API basis. E.g. for an API named
v1, config is stored in ajson-api-v1.phpfile. - Store adapters now relate to a specific resource type, and also contain all filtering/pagination logic for an index HTTP request.
- The validators class now provides query parameter validation rules rather than rules specifically for the filter query parameter.
- Pagination is now implemented via a pagination strategy that is injected into the
EloquentAdapter. This allows for pagination strategies to be changed on a per-resource type basis. The package includes aStandardStrategythat integrates with the default Laravel page number/size pagination.
- A resource's
Requestclass has been removed as its functionality is now handled by middleware, and query parameter checking has been moved to theValidatorsclass. Searchclasses have been removed in favour of the new store adapters.- Package no longer supports Laravel 5.1 and 5.2.
- Shortcut for non-Eloquent generation on generator commands has been changed to
-N(was previously-newhich did not work).
- Default Eloquent hydration attributes are now calculated using
Model::getFillable(). To use this, set the$attributesproperty on an Eloquent hydrator tonull. - Eloquent hydrator will now calculate attributes to serialize as dates using
Model::getDates(). To use this, set the$datesproperty on an Eloquent hydrator tonull. - Default Eloquent serialization attribution in the
EloquentSchemaclass. These are calculated using eitherModel::getVisible()orModel::getFillable()minus anyModel::getHidden()keys. To use this, set the$attributesproperty on an Eloquent schema tonull.
- When generating an Eloquent hydrator or schema using the
make:json-apicommands, the$attributesproperty will be set asnullby default.
- Corrected mistake in description of the
make:json-api:validatorsArtisan command.
- Updated service provider bindings for the
neomerx/json-apifactories.
- Added support for Laravel 5.4. However, consuming applications will need to use the Browserkit testing package to continue to use the JSON API testing suite.
- Dropped support for PHP 5.5
- Bug in Eloquent adapter meant that a check for whether a resource identifier exists was checking whether the whole table had any rows, rather than the specific id.
- #31 Fix expression in abstract generator command that is not compatible with PHP 5.5
- Generator commands to generate the classes required for a JSON API resource. To view available commands use
php artisan list make:json-api. The main command ismake:json-api:resourcewhich generates multiple classes for a JSON API resource at once. Credit to @jstoone for contributing this feature.
- Dependency
symfony/psr-http-message-bridgenow allows^1.0as version 1 has now been released. Version0.2.*is still allowed to maintain backwards compatibility but will be removed inv0.6of this package.
- Amended testing that a model has been trashed so that it is compatible with Laravel 5.2 and 5.3.
This release is the first release to support Laravel 5.3.
- Can now attach custom adapters to the store via the
json-api.phpconfig file. - Authorizer now supports adding error messages from the error repository using string keys.
- An abstract Eloquent model hydrator can now be used.
- The Eloquent controller now handles saving of has many relationships that need to be committed to the database
after the primary model has been created. You must be using the new Eloquent hydrator for this to work, or your
existing hydrator can type hint the capability by implementing the new
HydratesRelatedInterface.
- Paging configuration is now held on a per-API basis.
- Update authorization can now access the resource submitted by the client via an additional method argument.
- Request handlers are now not injected to a controller via the constructor: instead the fully qualified class name is passed and controller middleware is used to validate requests. This change was necessary to support Laravel 5.3, while maintaining support for 5.1 and 5.2.
- Various classes have been moved into the
cloudcreativity/json-apipackage (changing their namespace), because the implementations are now framework agnostic. - Eloquent schemas now follow the JSON API recommendation and use hyphenated member names by default. This behaviour can however be overridden, e.g. if the Eloquent underscored attribute names is the desired convention.
- To match this, the search class also assumed a default of hyphenated member names, although this can be overridden.
- Validator provides now receive the resource type that they are validating into their method signatures. This allows for a single validator provider to validate multiple resource types if desired.
AbstractSortedSearchwas removed and its capability merged intoAbstractSearchas there was no need to have the two separate classes.- Removed the experimental
bootfeature on the JSON API service.
- Return value from hydrator was not being used in the Eloquent controller. The hydrator interface defines that the hydrated object should be returned, so the controller has been amended to respect this return value.
- Tied the package to Laravel
5.1.*|5.2.*. This is non-breaking because the package currently only works with these two versions (it was previously tied to^5.1). A breaking change in Laravel5.3means that this package does not currently work with5.3.
- Paginator now includes sort order in paging links. This is required because otherwise the paging does not maintain its order when using the links.
AbstractSortedSearchnow has adefaultSortmethod that is invoked if the client has not sent any sort parameters. Child classes can override this method to implement a default search order if desired.- Added
saving,saved,deletinganddeletedhooks to theEloquentController.
- Can now register a resource type with the resource registrar without providing a controller name. The controller
will default to the studley case of the resource type with
Controllerappended - e.g.postsbecomesPostsController. - New
InteractsWithResourcestest helper. This extendsMakesJsonApiRequestsand adds in helpers for using when a test case is testing a single resource type.
- Support for find-many requests in the default Eloquent model search implementation.
- Hooks in
EloquentControllerforcreating,created,updatingandupdatedevents. This makes it easier for child classes to implement customer logic, e.g. dispatching events, jobs, etc.
- Removed dependency between model test helper and Laravel's database test helper, as there was no need for this dependency to exist.
- Asserting that a model has been created now correctly checks expected attributes.
This is a substantial refactoring, based on using this package in production environments. We also updated the underlying packages, both of which are breaking changes:
neomerx/json-apifrom^0.6.6to^0.8.0cloudcreativity/json-apifrom^0.4.0to^0.5.0
Future changelog entries will document changes from this point onwards.