From c35a05b8f83d072103056b48bcf4ece53f8db372 Mon Sep 17 00:00:00 2001 From: sundayenglish Date: Tue, 24 Jun 2025 11:35:19 +0700 Subject: [PATCH] Add Permission --- app/Components/Permission/Manager.php | 35 +++++++++++++++------------ 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/app/Components/Permission/Manager.php b/app/Components/Permission/Manager.php index 9f70f0c..6be8c9f 100644 --- a/app/Components/Permission/Manager.php +++ b/app/Components/Permission/Manager.php @@ -1,13 +1,16 @@ 'showIndex', - ]; + // Khi sự kiện 'permissionSaved' được dispatch, gọi showIndex() + #[On('permissionSaved')] + public function showIndex() + { + $this->mode = 'index'; + $this->resetPage(); + $this->name = ''; + $this->editingId = null; + } // Khi search thay đổi, reset pagination public function updatingSearch() @@ -35,15 +44,6 @@ class Manager extends Component : ''; } - // Quay về index, refresh list - public function showIndex() - { - $this->mode = 'index'; - $this->resetPage(); - $this->name = ''; - $this->editingId = null; - } - // Xóa public function delete(int $id) { @@ -55,8 +55,10 @@ class Manager extends Component // Lưu form public function save() { - $rules = ['name' => 'required|string|unique:permissions,name' - .($this->editingId ? ",{$this->editingId}" : '')]; + $rules = [ + 'name' => 'required|string|unique:permissions,name' + . ($this->editingId ? ",{$this->editingId}" : '') + ]; $this->validate($rules); @@ -66,9 +68,12 @@ class Manager extends Component ); session()->flash('message', 'Permission saved.'); - $this->emit('permissionSaved'); + + // Gọi sự kiện nội bộ Livewire 3 + $this->dispatch('permissionSaved'); } + // Render view public function render() { $permissions = Permission::where('name', 'like', "%{$this->search}%")