Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support array of enum #60

Open
lokken opened this issue May 26, 2023 · 4 comments
Open

Support array of enum #60

lokken opened this issue May 26, 2023 · 4 comments
Labels
bug Something isn't working Stale

Comments

@lokken
Copy link

lokken commented May 26, 2023

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
Copy link
Member

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
Copy link
Author

lokken commented Jun 9, 2023

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

@github-actions
Copy link

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 github-actions bot added the Stale label Jul 29, 2023
@tcampbPPU tcampbPPU added bug Something isn't working and removed Stale labels Jul 29, 2023
@github-actions
Copy link

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 github-actions bot added the Stale label Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale
Projects
None yet
Development

No branches or pull requests

2 participants