-
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
[5.5] Optional parameter binding #17521
[5.5] Optional parameter binding #17521
Conversation
How is this different than the other PR? |
@taylorotwell you mean #16926? I guess there's some overlap (in fact I see now we have a conflict in a method) but this one was directed specifically at what we've been discussing at #13988, regarding the implicit binding of Eloquent models when the route as well as the controller method are defined with optional parameters. |
Why? What if they want to show a custom 404 or some redirect? I agree that injecting an empty model makes no sense. |
@JosephSilber well, mostly for consistence with the current behavior. From the docs:
If you want to do custom things, you can always customize the exception handler, or bind explicitly. As I see it, optional parameter should mean "what to do when no parameter is supplied" (that is, bind |
Can you provide a simple route and explicit binding an example I can paste into an app to see the currently broken behavior? |
@taylorotwell Sure. I just tried this in a 5.3 application:
For |
The empty models was on purpose to stick with current behaviour. :) |
I think this makes sense. |
(References Issue #13988)
Following @powelski 's reasoning, the behavior as implemented would be:
null
when the request did have a parameter didn't make much sense to me)null
if no parameter is in URI (according to the default parameter value indicated by the developer).(PR submitted to master even though it was tagged [5.3], for backwards compatibility)