session = $session; } /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $isLoggedIn = $request->path() != 'login'; if(! session('lastActivityTime')) $this->session->put('lastActivityTime', time()); elseif(time() - $this->session->get('lastActivityTime') > $this->timeout){ $this->session->forget('lastActivityTime'); $cookie = cookie('intend', $isLoggedIn ? url()->current() : 'home'); // auth()->logout(); Auth::logout(); return Redirect::route('login'); } $isLoggedIn ? $this->session->put('lastActivityTime', time()) : $this->session->forget('lastActivityTime'); return $next($request); } }