Laravel Auth失败,重复的用户电子邮件

时间:2019-06-13 12:17:53

标签: laravel authentication

我的应用程序需要多次存储同一用户。这是因为删除用户后,我进行了逻辑排除,只是更改了用户表中的状态字段。但是,如果我有两个用户使用同一封电子邮件,则Laravel身份验证失败。我该如何解决这个问题?如何定制身份验证以考虑此状态字段?

2 个答案:

答案 0 :(得分:4)

您可以添加自定义条件,例如:

if ( Auth::attempt(['email' => $email, 'password' => $password, 'status' => 1]) ) {
    // The user is active, not suspended, and exists.
}

答案 1 :(得分:0)

在LoginController中,您可以覆盖AuthenticatesUsers特征中存在的凭据方法

/**
 * Get the needed authorization credentials from the request.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return array
 */
protected function credentials(Request $request)
{
    // return ['email' => .., 'password' => .., 'status' => 1];

    return $request->only($this->username(), 'password');
}