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'
)
) {
$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,