Skip to content

Commit

Permalink
[Feature] Allow the default resource class to be set
Browse files Browse the repository at this point in the history
See #127
  • Loading branch information
lindyhopchris committed Jan 2, 2022
1 parent be308b0 commit 32fe61e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
20 changes: 18 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
All notable changes to this project will be documented in this file. This project adheres to
[Semantic Versioning](http://semver.org/) and [this changelog format](http://keepachangelog.com/).

## Unreleased

### 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](https://github.com/laravel-json-api/laravel/issues/127) The `JsonApiResource` class now has a
protected `serializeRelation` method that can be used to override the default serialization of relationships if
needed.

### Fixed

- [#130](https://github.com/laravel-json-api/laravel/issues/130) The `JsonApiResource` now correctly handles conditional
fields when iterating over relationships to find a specific relation.

## [1.0.1] - 2021-12-08

### Changed
Expand All @@ -13,8 +29,8 @@ All notable changes to this project will be documented in this file. This projec
### Fixed

- [#139](https://github.com/laravel-json-api/laravel/issues/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
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.

## [1.0.0] - 2021-07-31
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"require": {
"php": "^7.4|8.0.*",
"ext-json": "*",
"laravel-json-api/core": "^1.0.0",
"laravel-json-api/core": "^1.1",
"laravel-json-api/eloquent": "^1.0.1",
"laravel-json-api/encoder-neomerx": "^1.0.0",
"laravel-json-api/exceptions": "^1.0.0",
Expand Down Expand Up @@ -67,7 +67,7 @@
]
}
},
"minimum-stability": "stable",
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"sort-packages": true
Expand Down
14 changes: 14 additions & 0 deletions src/LaravelJsonApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use InvalidArgumentException;
use LaravelJsonApi\Core\Auth\AuthorizerResolver;
use LaravelJsonApi\Core\Query\Custom\ExtendedQueryParameters;
use LaravelJsonApi\Core\Resources\ResourceResolver;
use LaravelJsonApi\Eloquent\Resources\Relation;
use LaravelJsonApi\Laravel\Http\Requests\RequestResolver;

Expand Down Expand Up @@ -58,6 +59,19 @@ public static function defaultAuthorizer(string $authorizerClass): self
return new self();
}

/**
* Set the default resource class.
*
* @param string $resourceClass
* @return LaravelJsonApi
*/
public static function defaultResource(string $resourceClass): self
{
ResourceResolver::useDefault($resourceClass);

return new self();
}

/**
* Register a HTTP query class for the supplied resource type or types.
*
Expand Down

0 comments on commit 32fe61e

Please sign in to comment.