From aeb14074d21d09cf8fd58813e213410b572bb419 Mon Sep 17 00:00:00 2001 From: "allen.yan" Date: Sat, 10 May 2025 20:02:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=96=B0=E5=A2=9E=E8=AE=8A?= =?UTF-8?q?=E6=95=B8=E9=8C=AF=E8=AA=A4=E5=95=8F=E9=A1=8C=2020250510?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Livewire/Admin/ArtistForm.php | 2 +- app/Livewire/Admin/RoleForm.php | 2 +- app/Livewire/Admin/SongForm.php | 54 ++++++++++++++++++------------- app/Livewire/Admin/UserForm.php | 2 +- 4 files changed, 35 insertions(+), 25 deletions(-) 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([