Skip to content

Commit

Permalink
Update CanEagerLoadTrait.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Nov 26, 2024
1 parent 94a9f66 commit 53a77b6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Traits/CanEagerLoadTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 53a77b6

Please sign in to comment.