Home > Software design >  Laravel - how to disable web middleware group for some routes in web.php without editing kernel or a
Laravel - how to disable web middleware group for some routes in web.php without editing kernel or a

Time:07-28

I amm working on a laravel 8 project that encoded with source guardian and only file i can edit is routes/web.php and cant edit api.php

so how can i add routes to api group using web.php and disable web middleware group for them? i cant edit any file but web.php

CodePudding user response:

You can use the withoutMiddleware method to exclude middleware from routes:

Route::withoutMiddleware('web')->group(function () {
    // your routes without the 'web' middleware assigned
});

To mimic the group that the api.php file is loaded into you would have to add the 'api' middleware and a prefix:

Route::withoutMiddleware('web')->middleware('api')->prefix('api')->group(function () {
    ...
});

Laravel 8.x Docs - Middleware - Registering Middleware - withoutMiddleware

  • Related