feat: use generics of return type to determine resulting models (#1653)

This commit is contained in:
Casper Bloemendaal
2025-01-08 11:01:30 +01:00
committed by GitHub
parent bb1caed698
commit 271682a2a6
+5 -1
View File
@@ -819,10 +819,14 @@ class ModelsCommand extends Command
$relation === 'morphTo' $relation === 'morphTo'
) )
) { ) {
$matches = [];
$returnType = $this->getReturnTypeFromDocBlock($reflection);
preg_match('/MorphTo<(.+?)(?:,|>)/i', $returnType, $matches);
// Model isn't specified because relation is polymorphic // Model isn't specified because relation is polymorphic
$this->setProperty( $this->setProperty(
$method, $method,
$this->getClassNameInDestinationFile($model, Model::class) . '|\Eloquent', $matches[1] ?? $this->getClassNameInDestinationFile($model, Model::class) . '|\Eloquent',
true, true,
null, null,
$comment, $comment,