fix: Repository senza relationships

This commit is contained in:
Maicol Battistini 2023-06-16 15:30:02 +02:00
parent 1e30ba1527
commit eee6c06888
No known key found for this signature in database
1 changed files with 1 additions and 23 deletions

View File

@ -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;
}
}