TokenMismatchException in VerifyCsrfToken.php line 53 in Laravel 5.1

前端 未结 13 1241
独厮守ぢ
独厮守ぢ 2020-12-11 16:47

When I try to login show me token error. I have checked token in view form it\'s right and when comment \\App\\Http\\Middleware\\VerifyCsrfToken::class, in the

13条回答
  •  一生所求
    2020-12-11 17:03

    Well I think all missed the CSRF Token creation while logout!

    As I have solved out the problem.

    Just add below code to the header.

    
    
    

    And if you use {!!Form::open()!!} it will automatically create the token. Otherwise you can use

    
    

    or

    {!! csrf_field() !!}
    

    just immediate form open. Most importantly use return Redirect::to(''); on controller function or a page reload or ajax reload that the token can be created!

    Like:

    public function logout() {
        Session::flush();
        Auth::logout();
    
        return Redirect::to('/');
    }
    

    For ensure the token properly created or not check "view page source" on browser and it will shows like:

    
        
    
    
    

    I think it might solve the problem as it worked for me!

提交回复
热议问题