【发布时间】:2020-11-03 07:30:08
【问题描述】:
Laravel change password thrown with the message of Trying to get property 'password' of non-object", exception:
如何解决message: Trying to get property 'password' of non-object",异常: “ErrorException”请帮助..................................................
public function updateAuthUserPassword(Request $request)
{
$this->validate($request, [
'current' => 'required',
'newpassword' => 'required',
'password_confirmation' => 'required|same:newpassword'
]);
$user = User::find(Auth::id());
if (!Hash::check($request->current, $user->password)) {
return response()->json(['errors' => ['current'=> ['Current password does not match']]],
422);
}
$user->password = Hash::make($request->newpassword);
$user->save();
return $user;
}
【问题讨论】:
-
确保 $user 不为空