diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 8bdd55af1..7548288db 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -409,8 +409,6 @@ public function castPropertiesType($model) case 'immutable_datetime': $realType = '\Carbon\CarbonImmutable'; break; - case AsCollection::class: - case AsEnumCollection::class: case 'collection': $realType = '\Illuminate\Support\Collection'; break; @@ -436,6 +434,18 @@ public function castPropertiesType($model) continue; } + if (Str::startsWith($type, AsCollection::class)) { + $realType = $this->getTypeInModel($model, $params[0] ?? null) ?? '\Illuminate\Support\Collection'; + } + + if (Str::startsWith($type, AsEnumCollection::class)) { + $realType = '\Illuminate\Support\Collection'; + $relatedModel = $this->getTypeInModel($model, $params[0] ?? null); + if ($relatedModel) { + $realType = $this->getCollectionTypeHint($realType, $relatedModel); + } + } + $realType = $this->checkForCastableCasts($realType, $params); $realType = $this->checkForCustomLaravelCasts($realType); $realType = $this->getTypeOverride($realType);