From 271682a2a6d57691e1c7ff378f44e4ae6ac2aba0 Mon Sep 17 00:00:00 2001 From: Casper Bloemendaal Date: Wed, 8 Jan 2025 11:01:30 +0100 Subject: [PATCH] feat: use generics of return type to determine resulting models (#1653) --- src/Console/ModelsCommand.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index aa99282..1c643c6 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -819,10 +819,14 @@ class ModelsCommand extends Command $relation === 'morphTo' ) ) { + $matches = []; + $returnType = $this->getReturnTypeFromDocBlock($reflection); + preg_match('/MorphTo<(.+?)(?:,|>)/i', $returnType, $matches); + // Model isn't specified because relation is polymorphic $this->setProperty( $method, - $this->getClassNameInDestinationFile($model, Model::class) . '|\Eloquent', + $matches[1] ?? $this->getClassNameInDestinationFile($model, Model::class) . '|\Eloquent', true, null, $comment,