Sometimes, when laravel_session
cookie expired and I'm still on the page, I would log in and get the TokenMismatchException
error. This is understandable.
I would like to handle this case, e.g. by showing some kind of error to the user and redirecting. If possible, I would like to catch it only for the login request.
The main problem is that the CSRF token is checked by a global middleware, so the error gets thrown before I can handle it with try-catch
block in a controller action.
Another problem is that the VerifyCsrfToken.php in the app/Http/Middeware
directory, which looks like this:
class VerifyCsrfToken extends BaseVerifier
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
//
];
}
I can't see how I could use the code above to catch the TokenMismatchException
. Seems like I can only exclude specific URIs.
Is there any way I can do that?