Skip to content
This repository was archived by the owner on Feb 14, 2023. It is now read-only.

Commit 80fc7ac

Browse files
committed
Add nested relationships and includes on objects already included
1 parent 47fcbbd commit 80fc7ac

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/Http/Resources/RelationshipsWithIncludes.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,19 @@ protected function attachRelations(Model $model)
6565
/**
6666
* Process a model relation attaching to its model additional attributes.
6767
*
68-
* @param \Illuminate\Database\Eloquent\Model $relation
68+
* @param \Illuminate\Database\Eloquent\Model $model
6969
* @return array
7070
*/
71-
protected function processModelRelation(Model $relation)
71+
protected function processModelRelation(Model $model)
7272
{
73-
if (count(array_filter($relation->getRelations())) > 0) {
74-
$this->attachRelations($relation);
75-
$relation->setRelations([]);
76-
}
73+
$modelResource = new JsonApiResource($model, $this->authorize);
7774

78-
$relationResource = new JsonApiResource($relation, $this->authorize);
75+
$this->with['included'][] = $modelResource;
7976

80-
$this->with['included'][] = $relationResource;
77+
if (Arr::has($modelResource->with, 'included')) {
78+
$this->with['included'][] = $modelResource->with['included'];
79+
}
8180

82-
return $relationResource->getResourceIdentifier();
81+
return $modelResource->getResourceIdentifier();
8382
}
8483
}

0 commit comments

Comments
 (0)