修正新增變數錯誤問題 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 {
if ($canCreate) {
if ($this->canCreate) {
$artist = Artist::create($this->fields);
$this->notification()->send([
'icon' => 'success',

View File

@ -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([

View File

@ -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()

View File

@ -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([