validateWithBag('updatePassword', [ // 'current_password' => ['required', 'current_password'], // 'password' => ['required', Password::defaults(), 'confirmed'], // ]); // $request->user()->update([ // 'password' => Hash::make($validated['password']), // ]); // return back()->with('status', 'password-updated'); // } public function update(Request $request): RedirectResponse { try { $validated = $request->validateWithBag('updatePassword', [ 'current_password' => ['required', 'current_password'], 'password' => ['required', Password::defaults(), 'confirmed'], ]); $request->user()->update([ 'password' => Hash::make($validated['password']), ]); return back()->with('success-password', 'Password berhasil diperbarui.'); } catch (ValidationException $e) { return back()->withErrors($e->errors(), 'updatePassword')->with('error-password', 'Gagal memperbarui password. Silakan periksa kembali masukan Anda.'); } catch (\Exception $e) { return back()->with('error-password', 'Gagal memperbarui password. Silakan coba lagi.'); } } }