How To Avoid TokenMismatchException On Logout

Websolutionstuff | Jun-29-2020 | Categories : Laravel

Many times we faced a Tokenmismatch error in laravel. This error occurs If you stay too long time on one form or if your system stays idle or if you are not active on your computer, and then again try to fill this form.

At that time you may get a TokenMismatchException error because the CSRF token won’t be the same. recently many times we found this problem in logout time. So, In this example, we will see you how to avoid it.

Normally, if you are not active for a long time in your system then you will get errors like the below screen print.

tokenmismatch

 

 

To avoid the TokenMismatchException error, we may add exceptions for the URLs that we don’t want to have CSRF protection. There are special array for that in app/Http/Middleware/VerifyCsrfToken.php

class VerifyCsrfToken extends Middleware
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        //
    ];
}

So what we need to do, is just add logout into this array.

protected $except = [
    '/logout'
];

If you want to add more URLs then you can add them here.

 


You might also like:

Recommended Post
Featured Post
Laravel whereMonth and whereYear Example
Laravel whereMonth and whereYe...

In this article, we will show you laravel whereMonth and whereYear examples. whereMonth and whereYear are...

Read More

Jan-25-2021

How to Download File on the FTP Server Using PHP
How to Download File on the FT...

Today we will see how to download file on the ftp server using php. Many time we have requirment to retrieve file from t...

Read More

May-21-2021

Convert JSON String to JSON Object Javascript
Convert JSON String to JSON Ob...

In this example we will see convert JSON string to JSON object in Javascript. You can use the javascript JSON.parse...

Read More

Jul-14-2021

How to Check User Browser is Supported or Not in jQuery
How to Check User Browser is S...

In this article, we will see how to check user browser is supported or not in jquery. Some time latest features are not...

Read More

Nov-13-2020