This repository was archived by the owner on Feb 14, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
88## [ Unreleased]
99
10+ ## [ 2.0.2] - 2020-11-11
11+
12+ ### Added
13+
14+ - Relations with custom API resource classes
15+
1016## [ 2.0.1] - 2020-07-02
1117
1218### Added
Original file line number Diff line number Diff line change @@ -78,7 +78,9 @@ protected function attachRelations(Model $model)
7878 */
7979 protected function processModelRelation (Model $ model )
8080 {
81- $ modelResource = new JsonApiResource ($ model , $ this ->authorise );
81+ $ modelResourceClass = $ this ->getModelResource ($ model );
82+ /** @var \SkoreLabs\JsonApi\Http\Resources\JsonApiResource $modelResource */
83+ $ modelResource = new $ modelResourceClass ($ model , $ this ->authorise );
8284 $ modelIdentifier = $ modelResource ->getResourceIdentifier ();
8385
8486 if (!empty (Arr::get ($ modelIdentifier , $ model ->getKeyName (), null ))) {
@@ -137,4 +139,17 @@ protected function checkUniqueness(Collection $collection)
137139 return implode ('' , $ resource ->getResourceIdentifier ());
138140 });
139141 }
142+
143+ /**
144+ * Get API resource from model.
145+ *
146+ * @param \Illuminate\Database\Eloquent\Model $model
147+ * @return string
148+ */
149+ protected function getModelResource (Model $ model )
150+ {
151+ return defined (get_class ($ model ) . '::JSON_SERIALIZER ' )
152+ ? $ model ::JSON_SERIALIZER
153+ : JsonApiResource::class;
154+ }
140155}
You can’t perform that action at this time.
0 commit comments