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

[9.x] Allow using backed enums as route parameters #43294

Merged
merged 1 commit into from
Jul 20, 2022

Conversation

Neol3108
Copy link
Contributor

This PR adds support for using backed enum values as route parameters.

Example/Reasoning

I have a project where I have 2 models, Model1 and Model2. Where Model1 hasMany Model2.
Each Model1 can have one Model2 for each backed enum case. In my DB there is a unique constraint on model1_id and enum_value.
Then I have a route /model1/{model1}/model2/{model2:enum_value} (scoped).

This works fine, except every time I want to generate an URL from a named route I have to specify $model2->enum_value->value instead of just $model2.

Breaking changes

I can't think of any, except for if you expect an Object of class <YourBackedEnum> could not be converted to string error. Correct me if I'm wrong tho.

@taylorotwell taylorotwell merged commit 3cb5557 into laravel:9.x Jul 20, 2022
@Neol3108 Neol3108 deleted the enum-route-params branch July 21, 2022 17:16
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.

2 participants