Laravel 9 Route Group Controller Tutorial
Jul 27, 2022 . Admin
Now, let's see example of Assigning a controller to a route group. you'll learn Grouping routes by controllers in Laravel. it's simple example of Laravel 9 route group with controller. I explained simply step by step How To Use Controller Route Groups in Laravel. follow bellow step for laravel 9 group route controller example.
you may use the controller method to define the common controller for all of the routes within the group. Then, when defining the routes, you only need to provide the controller method that they invoke:
Example 1:use App\Http\Controllers\UserController; Route::controller(UserController::class)->group(function () { Route::get('/users/{id}', 'show'); Route::post('/users', 'store'); });Example 2:
use App\Http\Controllers\PostController; Route::controller(PostController::class)->group(function () { Route::get('/posts/{id}', 'show'); Route::post('/posts', 'store'); });
It will help you...