'', 'external_ip' =>'', 'enable' => true, ]; public function mount() { $this->canCreate = Auth::user()?->can('room-edit') ?? false; $this->canEdit = Auth::user()?->can('room-edit') ?? false; $this->canDelect = Auth::user()?->can('room-delete') ?? false; } public function openModal($id = null) { $this->resetFields(); if ($id) { $branch = Branch::findOrFail($id); $this->branchId = $branch->id; $this->fields = $branch->only(array_keys($this->fields)); } $this->showModal = true; } public function closeModal() { $this->resetFields(); $this->showModal = false; } public function save() { if ($this->branchId) { if ($this->canEdit) { $branch = Branch::findOrFail($this->branchId); $branch->update($this->fields); $this->notification()->send([ 'icon' => 'success', 'title' => '成功', 'description' => '分店已更新', ]); } } else { if ($this->canCreate) { $branch = Branch::create($this->fields); $this->notification()->send([ 'icon' => 'success', 'title' => '成功', 'description' => '分店已新增', ]); } } $this->resetFields(); $this->showModal = false; $this->dispatch('pg:eventRefresh-branch-table'); } public function deleteArtist($id) { if ($this->canDelect) { Branch::findOrFail($id)->delete(); $this->notification()->send([ 'icon' => 'success', 'title' => '成功', 'description' => '分店已刪除', ]); $this->dispatch('pg:eventRefresh-branch-table'); } } public function resetFields() { foreach ($this->fields as $key => $value) { if ($key == 'enable') { $this->fields[$key] = true; } else { $this->fields[$key] = ''; } } $this->branchId = null; } public function render() { return view('livewire.admin.branch-form'); } }