-
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
[11.x] middleware support for specific method in resource routes #53313
[11.x] middleware support for specific method in resource routes #53313
Conversation
… set middleware for specific methods on registered resource
…ability to set middleware for specific methods on registered resource
…t for setting middleware for specific methods on registered resources
Looks good to have 👍 |
One thing that gives me pause here is the order in which you call |
Thanks for reviewing and taking an interest in my PR! I'll take a look soon. |
4bd83d8
to
6ccf360
Compare
240df4b
to
ce7aa5d
Compare
…c methods on registered resources
ce7aa5d
to
d77b2ba
Compare
Wouldn't it be more intuitive if this was an associative array? This would be consistent with other resource methods: Route::resource('photos', PhotoController::class)->names([
'create' => 'photos.build'
]); |
Then we cannot achieve same list of Middleware for 2 or more methods 🤔 So if I need 2 Middleware for show and index then we need to repeat them. |
That is true, but would there be much harm in that compared to intuitive notation? Also, the idea of using |
@taylorotwell, I apologize for the delay. I've updated the code to respect the order and revised the tests accordingly. |
Enhancement: Middleware Assignment for Resource & Singleton Routes
This pull request enables assigning middleware to specific resourceful methods on resource and singleton routes within the Laravel framework. Key changes include new method 'middlewareFor` for method-specific middleware assignment and updates to resource registration logic to support these configurations.
Motivation: While most developers prefer using routes for defining middleware, this particular case necessitates defining it at the controller level. Alternatively, we could extract all routes into separate routes. Addressing this challenge will streamline our approach.
Examples after merging:
I'm up foraddedwithoutMiddlewareFor
if it's in demand.withoutMiddlewareFor
.