How to turn off CRSF protection for a route in Laravel

How to turn off CRSF protection for a route in Laravel

To turn off or diasble CRSF protection for specific routes in Laravel open “app/Http/Middleware/VerifyCsrfToken.php” file and add following code in it

//add this class
private $exceptUrls = [‘controller/route1’, ‘controller/route2’];

//modify 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);}