From 51fb97b8fb6d31683ba8557c6975647a35910cef Mon Sep 17 00:00:00 2001 From: uno-sw Date: Fri, 2 Aug 2024 13:08:55 +0900 Subject: [PATCH] Add support for AsCollection::using and AsEnumCollection::of casts --- src/Console/ModelsCommand.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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);