From 7a3bb146535425baf361b48ad244261a336365bc Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 21 Mar 2024 14:46:34 +0100 Subject: [PATCH] Refactor password validation and update button label --- app/Livewire/Profile/Index.php | 13 ++++++++----- resources/views/livewire/profile/index.blade.php | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/Livewire/Profile/Index.php b/app/Livewire/Profile/Index.php index abfc0b972..631d4f956 100644 --- a/app/Livewire/Profile/Index.php +++ b/app/Livewire/Profile/Index.php @@ -11,11 +11,8 @@ class Index extends Component public int $userId; public string $email; - #[Validate('required')] public string $current_password; - #[Validate('required|min:8')] public string $new_password; - #[Validate('required|min:8|same:new_password')] public string $new_password_confirmation; #[Validate('required')] @@ -29,7 +26,9 @@ class Index extends Component public function submit() { try { - $this->validate(); + $this->validate([ + 'name' => 'required', + ]); auth()->user()->update([ 'name' => $this->name, ]); @@ -42,7 +41,11 @@ class Index extends Component public function resetPassword() { try { - $this->validate(); + $this->validate([ + 'current_password' => 'required', + 'new_password' => 'required|min:8', + 'new_password_confirmation' => 'required|min:8|same:new_password', + ]); if (!Hash::check($this->current_password, auth()->user()->password)) { $this->dispatch('error', 'Current password is incorrect.'); return; diff --git a/resources/views/livewire/profile/index.blade.php b/resources/views/livewire/profile/index.blade.php index af4de1b2b..8f4dfe62b 100644 --- a/resources/views/livewire/profile/index.blade.php +++ b/resources/views/livewire/profile/index.blade.php @@ -13,8 +13,8 @@
-

Reset Password

- Reset +

Change Password

+ Save