From 8a0405a4e87e78415ede18529452773a9ada1cdf Mon Sep 17 00:00:00 2001 From: Jonas Staudenmeir Date: Sat, 15 Feb 2025 15:52:08 +0100 Subject: [PATCH 1/2] Support Laravel 12 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5b1c03c..8b24928 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Use this command if you are in PowerShell on Windows (e.g. in VS Code): | Laravel | Package | |:--------|:--------| +| 12.x | 2.17 | | 11.x | 2.16 | | 10.x | 2.13 | | 9.x | 2.12 | From 451496e4272c11d87b404791acdd352c606f29c0 Mon Sep 17 00:00:00 2001 From: Jonas Staudenmeir Date: Thu, 20 Feb 2025 20:20:43 +0100 Subject: [PATCH 2/2] Find BelongsToThrough relationships by return type (#114) --- src/IdeHelper/BelongsToThroughRelationsHook.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/IdeHelper/BelongsToThroughRelationsHook.php b/src/IdeHelper/BelongsToThroughRelationsHook.php index 33c036e..b49d447 100644 --- a/src/IdeHelper/BelongsToThroughRelationsHook.php +++ b/src/IdeHelper/BelongsToThroughRelationsHook.php @@ -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; @@ -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); } }