fumeapp / modeltyper

Generate TypeScript interfaces from Laravel Models
MIT License
130 stars 14 forks source link

Support array of enum #60

Open lokken opened 1 year ago

lokken commented 1 year ago

For instance, in User model

    protected $casts = [
        'database_roles' => AsEnumCollection::class.':'.DatabaseRole::class,
    ]

Here is the error when running the model:typer tool. Class "Illuminate\Database\Eloquent\Casts\AsEnumCollection:App\Enums\DatabaseRole" does not exist

It's a simple workaround to remove the AsEnumCollection temporarily, generate the types, and then add [] to the end of the generated type, but thought you may want to support this use case. Thanks, have a good one.

tcampbPPU commented 1 year ago

TIL didn't know you could cast Enum as AsEnumArrayObject or AsEnumCollection, that syntax might be a little tricky 😕

'statuses' => AsEnumCollection::class.':'.ServerStatus::class,

When you run php artisan model:show User what does that output for that database_roles look like?

lokken commented 1 year ago

It's Gollum's tricksy tricks. database_roles fillable..string(255) / Illuminate\Database\Eloquent\Casts\AsEnumCollection:App\Enums\DatabaseRole

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.