Created
May 15, 2015 06:57
-
-
Save petehouston/52494b48541e883a1e75 to your computer and use it in GitHub Desktop.
Exclude route from CSRF verification in Laravel 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace App\Http\Middleware; | |
use Closure; | |
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier; | |
class VerifyCsrfToken extends BaseVerifier { | |
/** | |
* Exclude route from CSRF check | |
* @var array | |
*/ | |
protected $excludeRoutes = [ | |
'home/exclude', | |
'page/about', | |
'page/terms', | |
// add any route to exclude here | |
]; | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next) | |
{ | |
foreach($this->excludeRoutes as $route) { | |
if ($request->is($route)) { | |
return $next($request); | |
} | |
} | |
return parent::handle($request, $next); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment