'delete', 'update' => 'update', ]; public function render() { return view('writeoff::livewire.branch.branch-modal'); } public function submit() { $this->validate(); // Validate the form input data DB::transaction(function () { // Prepare the data for creating a new user $data = [ 'kode' => $this->kode, 'name' => $this->name ]; if ($this->edit_mode) { // Emit a success event with a message $branch = Branch::find($this->id); $branch->update($data); $this->dispatch('success', __('Branch updated')); } else { // Emit a success event with a message Branch::create($data); $this->dispatch('success', __('New Branch created')); } }); // Reset the form fields after successful submission $this->reset(); } public function update($id) { $this->edit_mode = true; $branch = Branch::find($id); $this->id = $branch->id; $this->kode = $branch->kode; $this->name = $branch->name; } public function delete($id) { $branch = Branch::find($id); $branch->delete_by = auth()->user()->id; $branch->deleted_at = now(); $approval = [ 'method' => 'delete', 'menu' => 'Parameter Cabang', 'old_request' => json_encode($branch), 'description' => 'Delete Parameter Cabang', 'status' => '0', 'ref' => $branch->kode ]; $is_approval = Approval::where('menu', 'Parameter Cabang') ->where('ref', $branch->kode) ->where('status', '0') ->where('method', 'delete') ->get() ->first(); if ($is_approval) { $this->dispatch('error', 'Data Sedang Menunggu Approval'); } else { Approval::create($approval); $this->dispatch('success', 'Data Berhasil Di Hapus, Menunggu Approval'); } } public function hydrate() { $this->resetErrorBag(); $this->resetValidation(); } protected function rules() { if ($this->edit_mode) { $request = new UpdateBranchRequest(); } else { $request = new StoreBranchRequest(); } return $request->rules(); } }