[5.6] Allow nullable method injection#22488
[5.6] Allow nullable method injection#22488mpyw wants to merge 1 commit intolaravel:masterfrom mpyw-forks:nullable-dependency-injection
Conversation
|
This is a breaking change. It is better to PR it to master (5.6) |
|
Thank you for responding. I really want the feature like Polymorphic Route Model Binding. I hope it will be supported in the future version of Laravel. |
|
And where are the tests? |
|
Currently not yet. And I don't know how should I treat broken tests... |
|
There's nothing in this PR that is polymorphic, nor does it change the model binding. Don't call it that. If you really wanted something polymorphic, make it work with a Commentable interface that both Article and Event implements. Then use that in your action. Note that this change broke existing tests. That is a really bad sign. You need to modify your change so that it at least doesn't break existing code, and add tests that shows the new behavior. |
|
To clarify; you are not allowed to change any existing tests. They exist to make sure that things aren't broken. You have to change your code so that the existing tests keeps working. |
I already tried to do that, however, how can I define binding rule for each route? |
|
This isn't a good place to ask about these things. I suggest that you close this PR and ask in the chat at https://larachat.co/ or start a discussion at https://github.com/laravel/internals |
|
Okay |
|
Finally I got the solution by overriding |
I wrote the following controller action that can accept multiple routes. Some of injected arguments are nullable.
However, Laravel currently cannot handle null value injection. This PR makes it possible.
Related: 【Laravel】Route Model Binding と Policy だけで認可処理を完結させるための Resourceful ルーティングの工夫 - Qiita