Grouping routes to a controller in one step #36173
-
I like the array syntax for mapping Controller methods to routes. I noticed I have to repeat the controller for every single route. I was thinking it would be cool, if we can group a whole block of routes to a controller in one step (See example below). What do you think? // instead of doing this
Route::get('foo', [BlogController::class, 'getFoo']);
Route::get('bar', [BlogController::class, 'getBar']);
Route::get('baz', [BlogController::class, 'getBaz']);
// i was thinking, it would be cool, if we can do this
Route::controller(BlogController::class)->group(function () {
Route::get('foo', 'getFoo');
Route::get('bar', 'getBar');
Route::get('baz', 'getBaz');
}); |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I think that this part of documentation would be helpful: https://laravel.com/docs/8.x/controllers#restful-partial-resource-routes |
Beta Was this translation helpful? Give feedback.
-
This has been re-added in 8.x via #40276 after already having been historically available in older versions (e.g 4.x). |
Beta Was this translation helpful? Give feedback.
This has been re-added in 8.x via #40276 after already having been historically available in older versions (e.g 4.x).