['required', 'string'], 'password' => ['required', 'string', 'min:8', 'confirmed'], ]; public function mount(): void { $this->user = Auth::user(); $this->allRoles = Role::all()->pluck('name')->toArray(); $this->roles = $this->user->roles->pluck('name')->toArray(); } public function showPasswordForm(): void { $this->mode = 'password'; $this->resetErrorBag(); $this->resetValidation(); } public function showView(): void { $this->mode = 'view'; $this->reset(['currentPassword', 'password', 'password_confirmation']); $this->resetErrorBag(); } public function updatePassword(): void { // 1. Validate $this->validate(); if (! Hash::check($this->currentPassword, $this->user->password)) { $this->addError('currentPassword', 'Mật khẩu hiện tại không đúng.'); return; } $this->user->password = Hash::make($this->password); $this->user->save(); session()->flash('message', 'Đổi mật khẩu thành công.'); $this->showView(); } public function render() { return view('components.profile.manager', [ 'user' => $this->user, 'roles' => $this->roles, 'allRoles' => collect($this->allRoles), 'title' => 'My Profile', ]); } }