Skip to content

Instantly share code, notes, and snippets.

@petehouston
Created May 15, 2015 06:57
Show Gist options
  • Save petehouston/52494b48541e883a1e75 to your computer and use it in GitHub Desktop.
Save petehouston/52494b48541e883a1e75 to your computer and use it in GitHub Desktop.
Exclude route from CSRF verification in Laravel 5
<?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