Skip to content

Commit 32fe61e

Browse files
committed
[Feature] Allow the default resource class to be set
See #127
1 parent be308b0 commit 32fe61e

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

CHANGELOG.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
All notable changes to this project will be documented in this file. This project adheres to
44
[Semantic Versioning](http://semver.org/) and [this changelog format](http://keepachangelog.com/).
55

6+
## Unreleased
7+
8+
### Added
9+
10+
- The default JSON:API resource class can now be changed via
11+
the `LaravelJsonApi\Laravel\LaravelJsonApi::defaultResource()` method. This should be set in a service
12+
provider's `register()` method.
13+
- [#127](https://github.com/laravel-json-api/laravel/issues/127) The `JsonApiResource` class now has a
14+
protected `serializeRelation` method that can be used to override the default serialization of relationships if
15+
needed.
16+
17+
### Fixed
18+
19+
- [#130](https://github.com/laravel-json-api/laravel/issues/130) The `JsonApiResource` now correctly handles conditional
20+
fields when iterating over relationships to find a specific relation.
21+
622
## [1.0.1] - 2021-12-08
723

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

1531
- [#139](https://github.com/laravel-json-api/laravel/issues/139) Fix the `WhereHas` and `WhereDoesntHave` filters.
16-
Previously these were not iterating over the filters from the correct resource schema - they were iterating over
17-
the filters from the schema to which the relationship belonged. They now correctly iterate over the filters from the
32+
Previously these were not iterating over the filters from the correct resource schema - they were iterating over the
33+
filters from the schema to which the relationship belonged. They now correctly iterate over the filters from the
1834
schema for the resource that is on the inverse side of the relationship.
1935

2036
## [1.0.0] - 2021-07-31

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"require": {
2626
"php": "^7.4|8.0.*",
2727
"ext-json": "*",
28-
"laravel-json-api/core": "^1.0.0",
28+
"laravel-json-api/core": "^1.1",
2929
"laravel-json-api/eloquent": "^1.0.1",
3030
"laravel-json-api/encoder-neomerx": "^1.0.0",
3131
"laravel-json-api/exceptions": "^1.0.0",
@@ -67,7 +67,7 @@
6767
]
6868
}
6969
},
70-
"minimum-stability": "stable",
70+
"minimum-stability": "dev",
7171
"prefer-stable": true,
7272
"config": {
7373
"sort-packages": true

src/LaravelJsonApi.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use InvalidArgumentException;
2424
use LaravelJsonApi\Core\Auth\AuthorizerResolver;
2525
use LaravelJsonApi\Core\Query\Custom\ExtendedQueryParameters;
26+
use LaravelJsonApi\Core\Resources\ResourceResolver;
2627
use LaravelJsonApi\Eloquent\Resources\Relation;
2728
use LaravelJsonApi\Laravel\Http\Requests\RequestResolver;
2829

@@ -58,6 +59,19 @@ public static function defaultAuthorizer(string $authorizerClass): self
5859
return new self();
5960
}
6061

62+
/**
63+
* Set the default resource class.
64+
*
65+
* @param string $resourceClass
66+
* @return LaravelJsonApi
67+
*/
68+
public static function defaultResource(string $resourceClass): self
69+
{
70+
ResourceResolver::useDefault($resourceClass);
71+
72+
return new self();
73+
}
74+
6175
/**
6276
* Register a HTTP query class for the supplied resource type or types.
6377
*

0 commit comments

Comments
 (0)