How to disable CSRF validation in laravel?

    2 answers 2

    For 5.2:

    In app / Http / Middleware / VerifyCsrfToken.php, you can add the $ except variable and there specify the paths for which you do not need to check the token.

    protected $except = [ '/unprotected/*' ]; 

    In addition, if you need to disable it completely, you can also do this via app / Http / Kernel.php: in the $ middlewareGroups array in the Middleware you need, comment out the line:

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

      For GET requests, CSRF protection is disabled by default (see handle () in vendor / ... /VerifyCsrfToken.php ). The routes for POST requests look like this: / unprotected / profit or / unprotected / trifle . Those. in our case, the code is as follows

       protected $except = [ '/unprotected/*', '/unprotected/profit', '/unprotected/trifle', ]; 

      for POST requests / unprotected / profit , / unprotected / trifle and requests starting with / unprotected / .