我创建了更改密码的函数,但出现错误异常(尝试在 null 上读取属性“密码”)。有人可以建议处理这个例外吗?
public function passwordUpdate(Request $request){
// return $request->input();
$rules=[
'password'=>'required',
'newpassword'=>'required',
'cannewpassword'=>'same:newpassword'
];
$custommsg=[
'password.required'=>'Old password must be filled out.',
'newpassword.required'=>'New password must be filled out.',
'cannewpassword.required'=>'Confirm password must be filled out.',
];
$validate=Validator::make($request->all(),$rules,$custommsg);
if($validate->fails()){
return redirect('change-password')->withErrors($validate);
}
else{
$check=Hash::check($request->password,auth()->user()->password);
if($check){
$user=User::find(auth()->user()->id);
$user->update(['password'=>Hash::make($request->newpassword)]);
return redirect('change-password')->with('msg','Password Updated Successfully!');
}
else{
return redirect('change-password')->with('msg',"You have entered wrong Password!");
}
}
}