Last active
          January 26, 2016 21:50 
        
      - 
      
- 
        Save df-jablan/fe7799e654c595faa51c to your computer and use it in GitHub Desktop. 
    Laravel 5.1 handle Token Mismatch error from expired an session
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // app/Http/Middleware/Authenticate.php | |
| /** | |
| * Handle an incoming request. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @param \Closure $next | |
| * | |
| * @return mixed | |
| */ | |
| public function handle($request, Closure $next) | |
| { | |
| if ($this->auth->guest()) { | |
| return $request->ajax() ? response()->json('Unauthorized.', 401) : \Redirect::guest('auth/login'); | |
| } | |
| return $next($request); | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // app/Http/Middleware/VerifyCsrfToken.php | |
| /** | |
| * Handle an incoming request. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @param \Closure $next | |
| * | |
| * @return mixed | |
| */ | |
| public function handle($request, \Closure $next) | |
| { | |
| try { | |
| return parent::handle($request, $next); | |
| } catch (TokenMismatchException $_ex) { | |
| // Catch expired sessions | |
| return \Redirect::guest('auth/login')->withErrors([ | |
| 'Session Expired' => \Lang::get('session-expired', | |
| 'Your session has expired or is otherwise not valid.'), | |
| ]); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment