我想使用api
更改Laravel 9
中的密码我使用postman
,但遇到无法解决的问题我尝试了多种方法,但仍出现相同的错误
这是路由:
Route::get('changePassword', [AuthController::class, 'ChangePassword']);
这是模型:
这是控制器:
public function ChangePassword(Request $request)
{
$validator=Validator::make($request->all(),[
'old_password' =>'required',
'new_password' =>'required|min:8|max:30',
'confirm_password' =>'required|same:new_password'
]);
if ($validator->fails()) {
return response()->json([
'message'=>'validations fails',
'errors' =>$validator->errors()
],422);
}
$user=$request->user();
if (Hash::check($request->old_password,$user->password)) {
$user->update([
'password'=>Hash::make($request->password)
]);
return response()->json([
'message'=>' password successfully updated',
'errors' =>$validator->errors()
],200);
}
else
{
return response()->json([
'message'=>'old password does not match',
'errors' =>$validator->errors()
],422);
}
}
而我在 Postman 中得到的错误是:
有什么问题吗?
1条答案
按热度按时间k3fezbri1#
请尝试忘记new_password