Laravel 9 route group with controller

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

Answers 1
  • 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