Please what is wrong with this api code to update user password
public function updateCurrentPassword(Request $request){
$validator = Validator::make($request->all(),[
'current_pwd' => 'required|min:8',
'new_pwd' => 'required|min:8',
'confirm_pwd' => 'required|min:8',
]);
if($validator->fails()){
return response()->json(['validation_errors'=>$validator->messages()],422);
}else{
$userCount = User::where('id',$request->id)->count();
if($userCount > 0){
$user = User::where('id',$request->id)->first();
if(Hash::check($request->current_pwd,Auth::user()->password)){
//Check if new or confirm password is matching
if($request->new_pwd == $request->confirm_pwd){
User::where('id',Auth::user()->id)->update(['password'=>bcrypt($request->new_pwd)]);
}else{
return response()->json([
"status"=>false,
"message"=>"New Password does not match confirm password!"
],401);
}
}else{
return response()->json([
"status"=>false,
"message"=>"Current password entered is incorrect!"
],401);
}
return response()->json([
"status"=>true,
"message"=>"Password updated successfully!"
],201);
}else{
return response()->json([
"status"=>false,
"message"=>"User with this ID not found!"
],401);
}
}
}```
The error in my thunder client app is coming like ```ErrorException: Attempt to read property "password" on null in file D:\xampp\htdocs\jaano\jaanobackend\app\Http\Controllers\API\ApiV1UserController.php on line 149```
which is this line in my code ```if(Hash::check($request->current_pwd,Auth::user()->password)){```
Any help?