Skip to content

Commit 51fb97b

Browse files
committed
Add support for AsCollection::using and AsEnumCollection::of casts
1 parent 591e7d6 commit 51fb97b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/Console/ModelsCommand.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,6 @@ public function castPropertiesType($model)
409409
case 'immutable_datetime':
410410
$realType = '\Carbon\CarbonImmutable';
411411
break;
412-
case AsCollection::class:
413-
case AsEnumCollection::class:
414412
case 'collection':
415413
$realType = '\Illuminate\Support\Collection';
416414
break;
@@ -436,6 +434,18 @@ public function castPropertiesType($model)
436434
continue;
437435
}
438436

437+
if (Str::startsWith($type, AsCollection::class)) {
438+
$realType = $this->getTypeInModel($model, $params[0] ?? null) ?? '\Illuminate\Support\Collection';
439+
}
440+
441+
if (Str::startsWith($type, AsEnumCollection::class)) {
442+
$realType = '\Illuminate\Support\Collection';
443+
$relatedModel = $this->getTypeInModel($model, $params[0] ?? null);
444+
if ($relatedModel) {
445+
$realType = $this->getCollectionTypeHint($realType, $relatedModel);
446+
}
447+
}
448+
439449
$realType = $this->checkForCastableCasts($realType, $params);
440450
$realType = $this->checkForCustomLaravelCasts($realType);
441451
$realType = $this->getTypeOverride($realType);

0 commit comments

Comments
 (0)