[11.x] middleware support for specific method in resource routes#53313
[11.x] middleware support for specific method in resource routes#53313taylorotwell merged 8 commits into
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. |
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 foraddedwithoutMiddlewareForif it's in demand.withoutMiddlewareFor.