Skip to content

Commit

Permalink
Add support for AsCollection::using and AsEnumCollection::of casts
Browse files Browse the repository at this point in the history
  • Loading branch information
uno-sw committed Aug 2, 2024
1 parent 591e7d6 commit 51fb97b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Console/ModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 51fb97b

Please sign in to comment.