Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

HarshithaNaidu's avatar

CSRF token is not working for the form action in laravel 5.2

CSRF token is not working for the form action in laravel 5.2 on the server.But it works in localhost. Even i used the following code in routes.php Route::group(['middleware' => 'web'], function () { // }); Keep getting the error as follows TokenMismatchException in VerifyCsrfToken.php line 67: Event i have change in RouterServieProvider and kernel.php pages but no use Please help me to solve this.And even validation is not working.

0 likes
15 replies
Qlic's avatar

If you have the latest version of L5.2, you should remove your manual web middleware declerations in your routes file as they are automatically added now, which will cause sessions to be overwritten.

Jaytee's avatar

Yep, check your Laravel version, version 5.2.27 (or 28) and above now include the web middleware on all routes.

HarshithaNaidu's avatar

@Qlic : i have removed in routes but still its giving error like "TokenMismatchException in VerifyCsrfToken.php line 67:" its not letting me to login .

Jaytee's avatar

Are you including the csrf_field on your forms?

HarshithaNaidu's avatar

Please if anyone knows the answer help me out. I could not able to fix this issue still .its been three days :(

hashb's avatar

Same here. Please help. It's a huge problem for me :(

This error is wasting my days! It's been more than 1 week!

Snapey's avatar

@hashb post your own question if you want help. There can be multiple reasons, and I'm sure HarshithaNaidu does not want emailing everytime someone tries to help you.

1 like
hemantadsl's avatar

Hello, I have just updated my framework to 5.2.36 and now i am facing the problem TokenMismatchException error and i can't login in my admin. Yes i have added proper CSRF_field and my all routes are in web middleware and FYI i also have my own custom middleware groups in my route files. I tried but not solved, anyone please help me asap. Thanks.

alainbelez's avatar

@hemantadsl remove the web middleware. it is added by default already. will reset the sessions when you add them again.

hemantadsl's avatar

I did it . But still getting same token mismatch error and @alainbelez how can we remove web middleware, i think it's responsible for session access. If i remove web middleware it gives me error for session not found. My token is passing properly as a request values with proper name "_token" and just want to fix this mismatch of token. Please provide solution, this error is come after when i updated my framework to L5.2.32. Is there any new release in Laravel for auth system.

alainbelez's avatar

@hemantadsl if you check the RouteServiceProvider.php


    protected function mapWebRoutes(Router $router)
    {
        $router->group([
            'namespace' => $this->namespace, 'middleware' => 'web',
        ], function ($router) {
            require app_path('Http/routes.php');
        });
    }

so it is enabled by default. just add your usual routes in routes.php

//this is still have the web middleware
Route::get('/', function () {
    return view('welcome');
});
1 like
skyusuf's avatar

am having the same issue too but after i tried the above solution, am still having this error message "BadMethodCallException in Builder.php line 2405:"

Snapey's avatar

@skyusuf if you want an answer, post a new question, state the error you are having and the version you are running.

1 like
skyusuf's avatar

Thanks snapey but i dont think it necessary again because i found the solution .

Please or to participate in this conversation.