Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Laravel 5.x CSRF Middleware with custom redirect
namespace App\Http\Middleware;
use Closure;
use Redirect;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
class VerifyCsrfToken extends BaseVerifier
* The URIs that should be excluded from CSRF verification.
* @var array
protected $except = [
public function handle( $request, Closure $next )
if (
$this->isReading($request) ||
$this->runningUnitTests() ||
$this->shouldPassThrough($request) ||
) {
return $this->addCookieToResponse($request, $next($request));
// redirect the user back to the last page and show error
return Redirect::back()->withErrors( ['Sorry, we could not verify your request. Please try again.'] );

This comment has been minimized.

Copy link

@RatJantaraksa RatJantaraksa commented Oct 31, 2016

Work only login page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.