cevin
cevin

Reputation: 43

How to disable default web middleware in Laravel5.2?

I have a server async notify route :

Route::post('notify/payment/{gateway}','Payment@receiveNotify')

How to disable default web middleware ? (session and verifycsrftoken)

Upvotes: 2

Views: 2130

Answers (4)

Mateusz Przybylek
Mateusz Przybylek

Reputation: 5925

Since Laravel 7.7 you can use method withoutMiddleware eg:

Route::post('notify/payment/{gateway}','Payment@receiveNotify')->withoutMiddleware(['csrf']);

Upvotes: 0

Frederick G. Sandalo
Frederick G. Sandalo

Reputation: 929

in my case, since I am using API based development, I just commented out this line in app/Http/Kernel.php

// \App\Http\Middleware\VerifyCsrfToken::class,

Upvotes: 0

Viral Solani
Viral Solani

Reputation: 840

Yes, you can Just remove the 'middleware' => 'web' block entirely and continue like you used to.

But I prefer below option.

Go to your app/providers/RouteServiceProvider.php file and update like below and as per you needs:

For e.g :

public function map(Router $router)
{
    $this->mapWebRoutes($router);
    $this->mapApiRoutes($router);
}


protected function mapWebRoutes(Router $router)
{
    $router->group([
        'namespace' => $this->namespace, 'middleware' => 'web',
    ], function ($router) {
        require app_path('Http/routes.php');
    });

}


protected function mapApiRoutes(Router $router)
{
     $router->group([
         'namespace' => $this->namespace, 'middleware' => 'api',
     ], function ($router) {
         require app_path('Http/routes-api.php');
     });
}

Upvotes: 0

tanerkay
tanerkay

Reputation: 3930

It's in the map() method of your RouteServiceProvider.

Keep in mind, the web middleware group is automatically applied to your default routes.php file by the RouteServiceProvider.

https://www.laravel.com/docs/5.2/middleware#middleware-groups

Upvotes: 3

Related Questions