Skip to content

Commit

Permalink
Find BelongsToThrough relationships by return type (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir authored Feb 20, 2025
1 parent 8a0405a commit 451496e
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/IdeHelper/BelongsToThroughRelationsHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Illuminate\Database\Eloquent\Relations\Relation;
use ReflectionClass;
use ReflectionMethod;
use Throwable;
use ReflectionNamedType;
use Znck\Eloquent\Relations\BelongsToThrough as BelongsToThroughRelation;
use Znck\Eloquent\Traits\BelongsToThrough as BelongsToThroughTrait;

Expand All @@ -30,13 +30,11 @@ public function run(ModelsCommand $command, Model $model): void
continue;
}

try {
if ($method->getReturnType() instanceof ReflectionNamedType
&& $method->getReturnType()->getName() === BelongsToThroughRelation::class) {
/** @var \Illuminate\Database\Eloquent\Relations\Relation<*, *, *> $relationship */
$relationship = $method->invoke($model);
} catch (Throwable) { // @codeCoverageIgnore
continue; // @codeCoverageIgnore
}

if ($relationship instanceof BelongsToThroughRelation) {
$this->addRelationship($command, $method, $relationship);
}
}
Expand Down

0 comments on commit 451496e

Please sign in to comment.