From 53a77b6b2d1c408c77f6649735fb0e21063f1944 Mon Sep 17 00:00:00 2001 From: Mohammad Alavi Date: Tue, 26 Nov 2024 20:57:34 +0330 Subject: [PATCH] Update CanEagerLoadTrait.php --- src/Traits/CanEagerLoadTrait.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Traits/CanEagerLoadTrait.php b/src/Traits/CanEagerLoadTrait.php index a0de3c225..727712416 100644 --- a/src/Traits/CanEagerLoadTrait.php +++ b/src/Traits/CanEagerLoadTrait.php @@ -24,9 +24,9 @@ protected function eagerLoadRequestedRelations(): void $this->scopeQuery(function (Builder|Model $model) { if (Request::has(config('apiato.requests.params.include', 'include'))) { $validIncludes = []; - foreach (Response::getRequestedIncludes() as $includeName) { + foreach (Response::getRequestedIncludesAsModelRelation() as $includeName) { $relationParts = explode('.', $includeName); - $camelCasedIncludeName = $this->validateNestedRelations($this->model, $relationParts); + $camelCasedIncludeName = $this->filterInvalidRelations($this->model, $relationParts); if ($camelCasedIncludeName) { $validIncludes[] = $camelCasedIncludeName; } @@ -39,7 +39,7 @@ protected function eagerLoadRequestedRelations(): void }); } - private function validateNestedRelations(Builder|Model $model, array $relationParts): string|null + private function filterInvalidRelations(Builder|Model $model, array $relationParts): string|null { if (empty($relationParts)) { return null; @@ -57,7 +57,7 @@ private function validateNestedRelations(Builder|Model $model, array $relationPa return $relation; } - $nextRelation = $this->validateNestedRelations($nextModel, $relationParts); + $nextRelation = $this->filterInvalidRelations($nextModel, $relationParts); if (is_null($nextRelation)) { return null;