Skip to content

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