创建了一个名为 ValidationRegister 的 FormRequest ,以稍微更改标准注册控制器。由于我在请求中看到了大多数支票。
这是验证本身:
public function rules()
{
return [
'name' => ['required', 'string', 'max:255'],
'surname' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
'gender' => ['nullable', 'string', 'max:10'],
'birthday' => ['nullable', 'string'],
'rules' => 'accepted',
];
}
问题的实质是如何替换控制器中的验证
标准验证:
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
各种各样的尝试,甚至达到了注册特征的改变
答案 0 :(得分:1)
在文件App/Http/Controllers/Auth/RegisterController
中,您可以覆盖特征方法register
。为了使自定义逻辑起作用,您可能还需要更改create方法,以保存新的经过验证的字段。
public class RegisterController {
public function register(ValidationRegister $request)
{
event(new Registered($user = $this->create($request->validated())));
$this->guard()->login($user);
return $this->registered($request, $user)
?: redirect($this->redirectPath());
}
}