【发布时间】:2021-10-06 09:46:21
【问题描述】:
我在 Laravel Auth 注册时收到此错误
Call to a member function validate() on null
该错误仅在验证通过时发生,当验证失败时,它显示返回到注册视图并显示正确的错误。 在 if 失败后我尝试 dd 但它没有达到它:
protected function validator(array $data){
$req = new Request($data);
//dd($req,$data);
$this->validate($req,
[
'name' => ['required', 'string', 'max:50','min:3'],
'email' => ['required','email', 'unique:users'],
'password' => ['required', 'min:8', 'confirmed'],
'uni' => ['required'],
'city' => ['required'],
],[
'required' => 'هذا الحقل مطلوب',
'email'=>'نمط البريد الالكتروني غير صحيح',
'min'=>'يجب إدخال 8 حروف عالأقل',
'email.unique' => 'هذا البريد الالكتروني مستخدم',
'confirmed'=>'الرجاء التأكد من كلمة المرور',
'max'=>'50 حرف هو أقصى حد يمكن إدخاله',
'name.min'=>'الاسم قصير جدا',
]);
}
protected function create(array $data){
if ($this->validator($data)->fails()) {
return Redirect::back()->withErrors($this->validator($data))
->withInput();
}
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'photo'=>'img/user.jfif',
'university'=>$data['uni'],
'city'=>$data['city'],
]);
}
RegisterController 的完整代码
https://pastebin.com/B8XcNbBR
和 RegistersUsers(堆栈跟踪显示错误的地方)
https://pastebin.com/BBTTStLL
【问题讨论】:
标签: laravel laravel-validation laravel-authentication