<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
use Illuminate\Session\TokenMismatchException;

class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        '/api/*',
    ];
    
    public function handle($request, Closure $next)
    {
        try {
            return parent::handle($request, $next); // TODO: Change the autogenerated stub
        } catch (TokenMismatchException $e) {
            return redirect()->back(303)->withInput($request->all())->with('flash_error', 'Ой! Похоже, что вы долго не отправляли форму. Попробуйте еше раз.');
        }
    }
}
