Hello Devs,

In this tutorial, we are going to learn how to disable csrf protection on specific routes in laravel.

Follow this step by step guide given below:




Disable CSRF Protection

routes\web.php

Route::post('route1', 'TestController@show1');
Route::post('route2', 'TestController@show2');

app\Http\Middleware\VerifyCsrfToken.php

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;

class VerifyCsrfToken extends Middleware
{
    /**
     * Indicates whether the XSRF-TOKEN cookie should be set on the response.
     *
     * @var bool
     */
    protected $addHttpCookie = true;

    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'route1', 'route2',
    ];
}


I hope this example helps you.