How to turn off CRSF protection for specific route in Laravel?

devquora
devquora

Posted On: Apr 19, 2024

 

To turn off CRSF protection in Laravel add following codes in “app/Http/Middleware/VerifyCsrfToken.php”

 
//add an array of Routes to skip CSRF check
private $exceptUrls = ['controller/route1', 'controller/route2'];
 //modify this function
public function handle($request, Closure $next) {
 //add this condition foreach($this->exceptUrls as $route) {
 if ($request->is($route)) {
  return $next($request);
 }
}
return parent::handle($request, $next);
} 

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Laravel Interview Questions

    What is Laravel?

    Laravel is a free open source "PHP framework" based on the MVC design pattern. It is created by Taylor Otwell...