From e743f4401177ba5bf339f2b4d07538dbbf78c423 Mon Sep 17 00:00:00 2001 From: Kirill Uksusov Date: Tue, 3 Mar 2020 13:48:00 +0400 Subject: [PATCH] Fixed #892 (#894) * Fixed #892 * #892 test added --- src/Console/ModelsCommand.php | 2 +- .../ModelsCommand/Relations/Models/Simple.php | 10 ++++++++++ tests/Console/ModelsCommand/Relations/Test.php | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 2b0622b..e0f8126 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -505,7 +505,7 @@ class ModelsCommand extends Command 'morphedByMany' => '\Illuminate\Database\Eloquent\Relations\MorphToMany' ) as $relation => $impl) { $search = '$this->' . $relation . '('; - if (stripos($code, $search) || $impl === (string)$type) { + if (stripos($code, $search) || ltrim($impl, '\\') === ltrim((string)$type, '\\')) { //Resolve the relation's model to a Relation object. $methodReflection = new \ReflectionMethod($model, $method); if ($methodReflection->getNumberOfParameters()) { diff --git a/tests/Console/ModelsCommand/Relations/Models/Simple.php b/tests/Console/ModelsCommand/Relations/Models/Simple.php index 84f5c87..4359773 100644 --- a/tests/Console/ModelsCommand/Relations/Models/Simple.php +++ b/tests/Console/ModelsCommand/Relations/Models/Simple.php @@ -36,6 +36,16 @@ class Simple extends Model return $this->belongsToMany(Simple::class); } + public function relationBelongsToManyWithSub(): BelongsToMany + { + return $this->belongsToMany(Simple::class)->where('foo', 'bar'); + } + + public function relationBelongsToManyWithSubAnother(): BelongsToMany + { + return $this->relationBelongsToManyWithSub()->where('foo', 'bar'); + } + public function relationMorphTo(): MorphTo { return $this->morphTo(); diff --git a/tests/Console/ModelsCommand/Relations/Test.php b/tests/Console/ModelsCommand/Relations/Test.php index 77f2a03..f2b9a31 100644 --- a/tests/Console/ModelsCommand/Relations/Test.php +++ b/tests/Console/ModelsCommand/Relations/Test.php @@ -74,6 +74,10 @@ use Illuminate\Database\Eloquent\Relations\MorphToMany; * @property-read \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\ModelsOtherNamespace\AnotherModel $relationBelongsToInAnotherNamespace * @property-read \Illuminate\Database\Eloquent\Collection|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple[] $relationBelongsToMany * @property-read int|null $relation_belongs_to_many_count + * @property-read \Illuminate\Database\Eloquent\Collection|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple[] $relationBelongsToManyWithSub + * @property-read int|null $relation_belongs_to_many_with_sub_count + * @property-read \Illuminate\Database\Eloquent\Collection|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple[] $relationBelongsToManyWithSubAnother + * @property-read int|null $relation_belongs_to_many_with_sub_another_count * @property-read \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\ModelsOtherNamespace\AnotherModel $relationBelongsToSameNameAsColumn * @property-read \Illuminate\Database\Eloquent\Collection|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple[] $relationHasMany * @property-read int|null $relation_has_many_count @@ -113,6 +117,16 @@ class Simple extends Model return $this->belongsToMany(Simple::class); } + public function relationBelongsToManyWithSub(): BelongsToMany + { + return $this->belongsToMany(Simple::class)->where('foo', 'bar'); + } + + public function relationBelongsToManyWithSubAnother(): BelongsToMany + { + return $this->relationBelongsToManyWithSub()->where('foo', 'bar'); + } + public function relationMorphTo(): MorphTo { return $this->morphTo();