$user = User::find($uid); try { if (!$token = JWTAuth::fromUser($user)) { return $this->onUnauthorized(); } } catch (JWTException $e) { return $this->onJwtGenerationError(); }