guest()) { if ($request->ajax()) { return response('Unauthorized.', 401); } else { return redirect()->guest('login'); } } else { /** @var User $user */ $user = Auth::user(); if (!$user->hasRole('owner')) { return redirect(route('home')); } } return $next($request); } }