/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param string|null $guard * @return mixed */ public function handle($request, Closure $next, $guard = null) { if (Auth::guard($guard)->guest()) { if ($request->ajax()) { dd('Unauthorized'); return response('Unauthorized.', 401); } else { session_start(); if (isset($_SESSION['cart'])) { if (\Request::all()) { array_push($_SESSION['cart'], \Request::all()); } } else { $_SESSION['cart'] = []; array_push($_SESSION['cart'], \Request::all()); } if (\Auth::guest()) { \Session::flash('need_to_login_message', 'You need to log in'); } // dd($_SESSION['cart']); return redirect()->guest('login'); } } return $next($request); }