修正新增變數錯誤問題 20250510

This commit is contained in:
allen.yan 2025-05-10 20:02:40 +08:00
parent ea0e10bb64
commit aeb14074d2
4 changed files with 35 additions and 25 deletions

View File

@ -77,7 +77,7 @@ class ArtistForm extends Component
]); ]);
} }
} else { } else {
if ($canCreate) { if ($this->canCreate) {
$artist = Artist::create($this->fields); $artist = Artist::create($this->fields);
$this->notification()->send([ $this->notification()->send([
'icon' => 'success', 'icon' => 'success',

View File

@ -71,7 +71,7 @@ class RoleForm extends Component
]); ]);
} }
} else { } else {
if ($canCreate) { if ($this->canCreate) {
$role = Role::create(['name' => $this->name]); $role = Role::create(['name' => $this->name]);
$role->syncPermissions($this->selectedPermissions); $role->syncPermissions($this->selectedPermissions);
$this->notification()->send([ $this->notification()->send([

View File

@ -96,24 +96,32 @@ class SongForm extends Component
//$this->validate(); //$this->validate();
if ($this->songId) { if ($this->songId) {
$song = Song::findOrFail($this->songId); if ($this->canEdit) {
$song->update($this->fields); $song = Song::findOrFail($this->songId);
$this->notification()->send([ $song->update($this->fields);
'icon' => 'success', // ⭐ 同步多對多關聯
'title' => '成功', $song->artists()->sync($this->selectedArtists ?? []);
'description' => '歌曲已更新', $song->categories()->sync($this->selectedCategories ?? []);
]); $this->notification()->send([
'icon' => 'success',
'title' => '成功',
'description' => '歌曲已更新',
]);
}
} else { } else {
$song = Song::create($this->fields); if ($this->canCreate) {
$this->notification()->send([ $song = Song::create($this->fields);
'icon' => 'success', // ⭐ 同步多對多關聯
'title' => '成功', $song->artists()->sync($this->selectedArtists ?? []);
'description' => '歌曲已新增', $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->resetFields();
$this->showModal = false; $this->showModal = false;
@ -122,12 +130,14 @@ class SongForm extends Component
public function deleteSong($id) public function deleteSong($id)
{ {
Song::findOrFail($id)->delete(); if ($this->canDelect) {
$this->notification()->send([ Song::findOrFail($id)->delete();
'icon' => 'success', $this->notification()->send([
'title' => '成功', 'icon' => 'success',
'description' => '歌曲已刪除', 'title' => '成功',
]); 'description' => '歌曲已刪除',
]);
}
} }
public function resetFields() public function resetFields()

View File

@ -98,7 +98,7 @@ class UserForm extends Component
]); ]);
} }
} else { } else {
if ($canCreate) { if ($this->canCreate) {
$user = User::create($this->fields); $user = User::create($this->fields);
$user->syncRoles($this->selectedRoles); $user->syncRoles($this->selectedRoles);
$this->notification()->send([ $this->notification()->send([