Skip to content

Commit 271682a

Browse files
authoredJan 8, 2025··
feat: use generics of return type to determine resulting models (#1653)
1 parent bb1caed commit 271682a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed
 

‎src/Console/ModelsCommand.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -819,10 +819,14 @@ public function getPropertiesFromMethods($model)
819819
$relation === 'morphTo'
820820
)
821821
) {
822+
$matches = [];
823+
$returnType = $this->getReturnTypeFromDocBlock($reflection);
824+
preg_match('/MorphTo<(.+?)(?:,|>)/i', $returnType, $matches);
825+
822826
// Model isn't specified because relation is polymorphic
823827
$this->setProperty(
824828
$method,
825-
$this->getClassNameInDestinationFile($model, Model::class) . '|\Eloquent',
829+
$matches[1] ?? $this->getClassNameInDestinationFile($model, Model::class) . '|\Eloquent',
826830
true,
827831
null,
828832
$comment,

0 commit comments

Comments
 (0)
Please sign in to comment.