CSRF with REST API laravel

VRK picture VRK · Jan 27, 2016 · Viewed 8.5k times · Source

I am new in laravel. I want to create REST API's with Laravel, I have used Dingo for it. Now my problem is when I am sending post request

CSRF token mismatch is error is throwing

and for web version we have used CSRF token for validating the request..

can anyone help me for solving CSRF token mismatch error in laravel 5.1.

Thanks in advance...

Answer

Simon Schnell picture Simon Schnell · Jul 10, 2017

In your app\http\Middleware\VerifyCsrfToken.php file.

edit $except property with:

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

This will exclude your api routes from CSRF verification.And keep it up for other things like your frontend.