Код: Выделить всё
Route::post('/change-password', function (Request $request) {
// Validate the request data
$request->validate([
'current_password' => 'required|string',
'new_password' => 'required|string|confirmed|min:8',
]);
// Check if the current password matches the user's current password
if (!Hash::check($request->current_password, $request->user()->password)) {
return response()->json([
'message' => 'The provided current password does not match your current password.',
], 422);
}
// Update the user's password
$request->user()->password = bcrypt($request->new_password);
$request->user()->save();
return response()->json([
'message' => 'Password has been changed successfully.',
], 200);
})->middleware('auth:sanctum')->name('password.change');
[Я не ищу пароль для сброса, я ищу смену пароля для аутентифицированного пользователя. ]
Я пробовал: user()->updated(), чат-бот с искусственным интеллектом.
Подробнее здесь: https://stackoverflow.com/questions/789 ... ravel-11-x
Мобильная версия