-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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] Adds implicit Enum
route binding
#40281
Conversation
@nunomaduro is there a specific reason that an integer backed enum type can't be used? |
* Update routing.md Added requirement of string-backed enums to "Implicit Enum Binding" as stated in laravel/framework#40281: >Now, it's important to keep in mind, that the given Enum needs to be a Backed Enum with a string backing type. Meaning that, the Enum header needs to look like this: >enum {{ EnumName }}: string * Update routing.md * Update routing.md Co-authored-by: Taylor Otwell <[email protected]>
I was thinking the same. And patching the code to allow for int-backed Enums works like a charm, because However, if the user tries to pass a string like However, I would love to see the docs being more explicit about this. It should be stated that |
This pull request introduces implicit
Enum
route binding for Laravel v9.x. So let's see an example:In other words, when the given argument matches one of the
Enum
cases, the code in this pull request will resolve the associatedEnum
for the route method / closure. Otherwise, will respond404 Not Found
, similar to Model route binding.Now, it's important to keep in mind, that the given
Enum
needs to be a Backed Enum with astring
backing type. Meaning that, theEnum
header needs to look like this:enum {{ EnumName }}: string