-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[5.3] Implement route binding substitution using a middleware #13548
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
Conversation
I definitely support this one. Having recently experienced an issue with wanting to go through another middleware before binding (because my binding relied on the existence of the session), I definitely think this would be a great addition, which should also be no larger upgrade step than the move to the |
Another use case I have for this is if an ID scheme has changed, and we need to redirect old URIs to the new scheme, we'd want to do this before the binding throws an exception and we end up with a 404 page. Alternatively, we may want to just transform the ID to the new scheme internally, and then continue to the route binding as if nothing had happened. |
Just to make sure I understand this correctly: Let's say your I think that can get a little messy, no? |
Better than nothing. The main use case I see isn't for custom binding middleware per route, it's just to overwrite the whole thing a single time. That way, there is no mess. |
@JosephSilber note the order of when bindings / auth happen is the same before / after this change. |
For those wishing this was in 5.2 as well:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/<yourusername>/framework"
}
],
|
Not something I'd actually recommend @mikemand. |
If you want this in 5.2, I'd actually recommend extending the classes in your code, not forking the framework. Always avoid forking stuff to load as dependencies at all costs. |
Or, just upgrade to L5.3. It's not too bad, but beware the docs are not done, and we could break more stuff, so you'd need to keep a close watch on this repo for a few more weeks. |
How would you go about extending the Router and changing visibility of the methods from
Exactly why I'm not updating just yet. |
Is possible. Note that you'd have to extend the application class too. |
I moved my apps over to 5.3 purely to so I could delete our custom code like this. I've had this middleware in my apps for months. Only moving it to the core now. |
I may just be stupid, but this change seems to have broken the ability to test routes that use model binding: #16260 |
Not only is this really elegant, but it also allows massive flexibility on when and how these bindings take place. It's a relatively common use case for people to want to run middlewares before the bindings take place for various reasons such as ACL, throttling, or whatever.
There is however a very minor upgrading requirement that people now need to register this new middleware.