diff --git a/app/Livewire/Admin/ArtistForm.php b/app/Livewire/Admin/ArtistForm.php index f799cdb..cd55898 100644 --- a/app/Livewire/Admin/ArtistForm.php +++ b/app/Livewire/Admin/ArtistForm.php @@ -77,7 +77,7 @@ class ArtistForm extends Component ]); } } else { - if ($canCreate) { + if ($this->canCreate) { $artist = Artist::create($this->fields); $this->notification()->send([ 'icon' => 'success', diff --git a/app/Livewire/Admin/RoleForm.php b/app/Livewire/Admin/RoleForm.php index aacfad4..d954564 100644 --- a/app/Livewire/Admin/RoleForm.php +++ b/app/Livewire/Admin/RoleForm.php @@ -71,7 +71,7 @@ class RoleForm extends Component ]); } } else { - if ($canCreate) { + if ($this->canCreate) { $role = Role::create(['name' => $this->name]); $role->syncPermissions($this->selectedPermissions); $this->notification()->send([ diff --git a/app/Livewire/Admin/SongForm.php b/app/Livewire/Admin/SongForm.php index 79ac39c..2d0e6a8 100644 --- a/app/Livewire/Admin/SongForm.php +++ b/app/Livewire/Admin/SongForm.php @@ -96,24 +96,32 @@ class SongForm extends Component //$this->validate(); if ($this->songId) { - $song = Song::findOrFail($this->songId); - $song->update($this->fields); - $this->notification()->send([ - 'icon' => 'success', - 'title' => '成功', - 'description' => '歌曲已更新', - ]); + if ($this->canEdit) { + $song = Song::findOrFail($this->songId); + $song->update($this->fields); + // ⭐ 同步多對多關聯 + $song->artists()->sync($this->selectedArtists ?? []); + $song->categories()->sync($this->selectedCategories ?? []); + $this->notification()->send([ + 'icon' => 'success', + 'title' => '成功', + 'description' => '歌曲已更新', + ]); + + } } else { - $song = Song::create($this->fields); - $this->notification()->send([ - 'icon' => 'success', - 'title' => '成功', - 'description' => '歌曲已新增', - ]); + if ($this->canCreate) { + $song = Song::create($this->fields); + // ⭐ 同步多對多關聯 + $song->artists()->sync($this->selectedArtists ?? []); + $song->categories()->sync($this->selectedCategories ?? []); + $this->notification()->send([ + 'icon' => 'success', + 'title' => '成功', + 'description' => '歌曲已新增', + ]); + } } - // ⭐ 同步多對多關聯 - $song->artists()->sync($this->selectedArtists ?? []); - $song->categories()->sync($this->selectedCategories ?? []); $this->resetFields(); $this->showModal = false; @@ -122,12 +130,14 @@ class SongForm extends Component public function deleteSong($id) { - Song::findOrFail($id)->delete(); - $this->notification()->send([ - 'icon' => 'success', - 'title' => '成功', - 'description' => '歌曲已刪除', - ]); + if ($this->canDelect) { + Song::findOrFail($id)->delete(); + $this->notification()->send([ + 'icon' => 'success', + 'title' => '成功', + 'description' => '歌曲已刪除', + ]); + } } public function resetFields() diff --git a/app/Livewire/Admin/UserForm.php b/app/Livewire/Admin/UserForm.php index ddb8c7a..3176dcc 100644 --- a/app/Livewire/Admin/UserForm.php +++ b/app/Livewire/Admin/UserForm.php @@ -98,7 +98,7 @@ class UserForm extends Component ]); } } else { - if ($canCreate) { + if ($this->canCreate) { $user = User::create($this->fields); $user->syncRoles($this->selectedRoles); $this->notification()->send([