Php Laravel 7如何在sendLoginResponse()函数中修改$response

Php Laravel 7如何在sendLoginResponse()函数中修改$response,php,reactjs,laravel,authentication,axios,Php,Reactjs,Laravel,Authentication,Axios,我使用React构建前端应用程序,使用内置身份验证路由/控制器的Laravel 7构建后端应用程序。我似乎不知道如何从React组件使用axios访问登录端点。此外,我还应该在前端为非管理员用户“隐藏”一些链接(我在模式中实现了角色,并创建了一个中间件来检查管理员角色),但我需要用户在Redux状态下的角色来执行此操作。如何修改sendLoginResponse()中的$response以添加此角色信息 /** * Send the response after the user was au

我使用React构建前端应用程序,使用内置身份验证路由/控制器的Laravel 7构建后端应用程序。我似乎不知道如何从React组件使用axios访问登录端点。此外,我还应该在前端为非管理员用户“隐藏”一些链接(我在模式中实现了角色,并创建了一个中间件来检查管理员角色),但我需要用户在Redux状态下的角色来执行此操作。如何修改sendLoginResponse()中的$response以添加此角色信息

/**
 * Send the response after the user was authenticated.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
protected function sendLoginResponse(Request $request)
{
    $request->session()->regenerate();

    $this->clearLoginAttempts($request);

    if ($response = $this->authenticated($request, $this->guard()->user())) {
        return $response;
    }

    return $request->wantsJson()
                ? new Response('', 204)
                : redirect()->intended($this->redirectPath());
}

您可以在用户模型上添加一个
角色
关系,并使用Eloquent
with('role')
访问该关系,然后在
$response
中返回该关系,因为您在身份验证后已经拥有用户的
id
。感谢您的评论!我似乎不明白如何将角色添加到$response中。你的意思是我可以用('role')做:$this->authenticated($request,$this->guard()->user()->它应该这样做吗?抱歉,如果我遗漏了一些东西,我是Laravel的新手。。