Laravel 9 route group with controller

Updated at 22-Feb-2022, By samar

Laravel 9 route group with controller

In this session, we are going to try to solve the "Laravel 9 route group with controller" puzzle by using the computer language.

You can group all the routes which utilize the same controller using controller method in Laravel 9.
  • Route grouping with controller

    --PATH routes\web.php
    use App\Http\Controllers\OrderController;
    Route::controller(OrderController::class)->group(function () {
        Route::get('/orders/{id}', 'show');
        Route::post('/orders', 'store');

    If a group of routes uses the same controller then you can group all the routes using the controller method.

    Additional Note:

    1. Create OrderController using php artisan command -  php artisan make:controller OrderController

    2. Import/use controller in routes/web.php using use App\Http\Controllers\OrderController;

Back to code snippet queries related laravel