Skip to content

[12.x] Add a default option when retrieving an enum from data #55735

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

Merged
merged 2 commits into from
May 14, 2025

Conversation

elbojoloco
Copy link
Contributor

Enables you to provide a default value when retrieving an enum from data which is consistent with other getters in the InteractsWithData trait An example use case is when you're handling GET params in a dashboard.

Old:

$chartType = request()->enum('chart_type', ChartTypeEnum::class) ?: ChartTypeEnum::Bar;

New:

$chartType = request()->enum('chart_type', ChartTypeEnum::class, ChartTypeEnum::Bar);

@shaedrich
Copy link
Contributor

Would be cool to have an attribute on the enum or a method or the like 🤔

@taylorotwell taylorotwell merged commit fc0c66f into laravel:12.x May 14, 2025
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants