laravel TokenMismatchException in ajax request

后端 未结 5 845
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 09:25

i\'m using resource group and use this filter to resolve TokenMismatchException problem:

Route::filter(\'csrf\', function($route, $request) {
           


        
5条回答
  •  清歌不尽
    2020-11-29 09:44

      
      
      Ajax Example
              
      
    
      
    
      
      
    
      
    
    
      
    This message will be replaced using Ajax. Click the button to replace the message.
    'getMessage()']); ?>

    and VerifyCsrfToken.php file add this function

    protected function tokensMatch($request)
    {
        // If request is an ajax request, then check to see if token matches token provider in
        // the header. This way, we can use CSRF protection in ajax requests also.
        $token = $request->ajax() ? $request->header('X-CSRF-Token') : $request->input('_token');
    
        return $request->session()->token() == $token;
    }
    

提交回复
热议问题