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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
//add this in your class
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);}
|