fix: Repository senza relationships
This commit is contained in:
parent
1e30ba1527
commit
eee6c06888
|
@ -171,7 +171,7 @@ abstract class Repository extends RestifyRepository
|
|||
}
|
||||
|
||||
// Remove included from relationships (we already have them in included)
|
||||
foreach ($data['data']['relationships'] as &$relationship) {
|
||||
foreach (($data['data']['relationships'] ?? []) as &$relationship) {
|
||||
Arr::forget($relationship, 'included');
|
||||
}
|
||||
|
||||
|
@ -276,26 +276,4 @@ abstract class Repository extends RestifyRepository
|
|||
...$relationships,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Relations mapper
|
||||
*/
|
||||
private function mapRelations(RestifyRepository|Collection|array|null $repository, RestifyRequest $request, array &$included): array|Collection|null
|
||||
{
|
||||
if ($repository instanceof Collection) {
|
||||
return $repository->map(fn (self $repository) => $this->mapRelations($repository, $request, $included));
|
||||
}
|
||||
|
||||
if ($repository instanceof self) {
|
||||
$included[] = $repository;
|
||||
$this->mapRelations($repository->resolveRelationships($request), $request, $included);
|
||||
|
||||
return [
|
||||
'type' => $repository->getType($request),
|
||||
'id' => $repository->getId($request),
|
||||
];
|
||||
}
|
||||
|
||||
return $repository;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue