在手册中,我可以阅读:
By default, Laravel uses the email field for authentication. If you would like to customize this, you may define a
username
method on yourLoginController
但是就我而言,我想使用
unique_id
我的公司提供的用于验证我的用户的字段。该字段不是用户名,所以我对使用 username()
感到很抱歉得到这个的方法。是否有另一种方法可以告诉 Laravel 身份验证使用除 email
以外的其他内容?验证我的用户?
最佳答案
您可以覆盖 validateLogin
和 credentials
Auth/LoginController 中的方法
protected function validateLogin(Request $request)
{
$request->validate([
'unique_id' => 'required',
'password' => 'required|string',
]);
}
protected function credentials(Request $request)
{
return array_merge($request->only('unique_id', 'password'));
}
关于php - 如何在 Laravel 中使用另一个字段进行身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60997946/