Answer the question
In order to leave comments, you need to log in
Have I implemented the method correctly?
Guys, did I implement the correct method to change the user's password? The code looks like this to me.
/**
* Change the user password.
*
* @param Request $request
* @return JsonResponse
*/
public function changePassword(Request $request): JsonResponse
{
$validator = Validator::make($request->all(), [
'current_password' => [
'required',
'string',
function ($attribute, $value, $fail) {
if (! Hash::check($value, Auth::user()->getAuthPassword())) {
$fail('The '.$attribute.' is invalid.');
}
},
],
'new_password' => 'required|string|min:8|confirmed'
]);
if ($validator->fails()) {
return response()->json($validator->errors()->getMessages(), 422);
}
$user = Auth::user();
$user->password = Hash::make($request->new_password);
$user->save();
// Не важно что возвращаем, это я потом поменяю.
return response()->json($user);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question