如何在 Laravel auth 中自定义 "email" 字段?
How to customize "email" field in Laravel auth?
我正在尝试自定义 Laravel 的身份验证字段。我在 "name" 和 "password" 字段上成功了,但在 "email" 字段上失败了。我仍然有错误:
SQLSTATE[42S22]: Column not found: 1054 "email" field unknown in where
clause.
我试图依赖这个 ,但它没有用。在 RegisterController,
中,我将 create
函数更改为以下内容。
protected function create(array $data)
{
return User::create([
'user_pseudo' => $data['name'],
'user_email' => $data['email'],
'usr_mdp' => bcrypt($data['password']),
]);
}
此错误可能来自 unique
validation of the email field in the validation
method. If there's no column name specified it will use the name of the field as the column name。
将正确的列名添加到应该在其中搜索电子邮件的规则,此错误应该消失:
RegisterController.php
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users,user_email'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
我正在尝试自定义 Laravel 的身份验证字段。我在 "name" 和 "password" 字段上成功了,但在 "email" 字段上失败了。我仍然有错误:
SQLSTATE[42S22]: Column not found: 1054 "email" field unknown in where clause.
我试图依赖这个 RegisterController,
中,我将 create
函数更改为以下内容。
protected function create(array $data)
{
return User::create([
'user_pseudo' => $data['name'],
'user_email' => $data['email'],
'usr_mdp' => bcrypt($data['password']),
]);
}
此错误可能来自 unique
validation of the email field in the validation
method. If there's no column name specified it will use the name of the field as the column name。
将正确的列名添加到应该在其中搜索电子邮件的规则,此错误应该消失:
RegisterController.php
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users,user_email'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}