Skip to content

Commit 0bb2f74

Browse files
committed
Load related from memory
1 parent 8ac211f commit 0bb2f74

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Repositories/Repository.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,12 @@ public function resolveRelationships($request): array
514514
with(explode(',', $request->get('related')), function ($relations) use ($request, &$withs) {
515515
foreach ($relations as $relation) {
516516
if (in_array($relation, static::getRelated())) {
517-
// @todo check if the resource has the relation
518-
/** * @var AbstractPaginator $paginator */
519-
$paginator = $this->resource->{$relation}()->take($request->input('relatablePerPage') ?? (static::$defaultRelatablePerPage ?? RestifySearchable::DEFAULT_RELATABLE_PER_PAGE))->get();
517+
if ($this->resource->relationLoaded($relation)) {
518+
$paginator = $this->resource->{$relation};
519+
} else {
520+
/** * @var AbstractPaginator $paginator */
521+
$paginator = $this->resource->{$relation}()->take($request->input('relatablePerPage') ?? (static::$defaultRelatablePerPage ?? RestifySearchable::DEFAULT_RELATABLE_PER_PAGE))->get();
522+
}
520523

521524
$withs[$relation] = $paginator->map(fn (Model $item) => [
522525
'attributes' => $item->toArray(),

0 commit comments

Comments
 (0)