Laravel 9 route group with controller

Created 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

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.