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

[11.x] Replace all backed enums with values when building URLs #51524

Merged
merged 2 commits into from
May 21, 2024

Conversation

stefanvdlugt
Copy link
Contributor

When building a URL, the UrlGenerator takes each parameter that is a backed enum instance, and replaces it with its underlying value. This PR lets the UrlGenerator also replace backed enums that are nested more deeply in the $parameters array. This is useful when passing an array of enums as one of the parameters, for example when adding a filter query parameter.

Example:

route('foo', ['filters' => [MyEnum::One, MyEnum::Two]])
= http://example.com/foo?filters%5B0%5D=one&filters%5B1%5D=two

Previous behavior:

You'd get this URL from the above command, which includes the name and value of each enum instance separately:

= http://example.com/foo?filters%5B0%5D%5Bname%5D=One&filters%5B0%5D%5Bvalue%5D=one&filters%5B1%5D%5Bname%5D=Two&filters%5B1%5D%5Bvalue%5D=two

In order to get the shorter URL you'd have to add ->value to each enum instance.

Breaking changes

None as far as I can tell, unless you were using arrays of enum instances as parameter values as in the above example. I don't assume anyone did, looking at the format of the above URL, but maybe I'm missing something.

Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@stefanvdlugt stefanvdlugt marked this pull request as ready for review May 21, 2024 13:16
@stefanvdlugt stefanvdlugt changed the title Replace all backed enums with values when building URLs [11.x] Replace all backed enums with values when building URLs May 21, 2024
@taylorotwell taylorotwell merged commit cb567d3 into laravel:11.x May 21, 2024
28 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.

2 participants