'delete', 'update' => 'update', ]; public function render() { $cabang = Branch::all(); return view('writeoff::livewire.debitur.debitur-modal', compact('cabang')); } 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, 'branch_id' => $this->branch_id, 'status' => $this->status, 'address' => $this->address, 'npwp' => $this->npwp, 'registered_at' => $this->registered_at, ]; if ($this->edit_mode) { // Emit a success event with a message $debitur = Debitur::find($this->id); $debitur->update($data); $this->dispatch('success', __('Debitur updated')); } else { // Emit a success event with a message Debitur::create($data); $this->dispatch('success', __('New Debitur created')); } }); // Reset the form fields after successful submission $this->reset(); } public function update($id) { $this->edit_mode = true; $debitur = Debitur::find($id); $this->id = $debitur->id; $this->kode = $debitur->kode; $this->name = $debitur->name; $this->branch_id = $debitur->branch_id; $this->status = $debitur->status==1?true:false; $this->address = $debitur->address; $this->npwp = $debitur->npwp; $this->registered_at = $debitur->registered_at; } public function delete($id) { Debitur::destroy($id); // Emit a success event with a message $this->dispatch('success', 'Debitur successfully deleted'); } public function hydrate() { $this->resetErrorBag(); $this->resetValidation(); } protected function rules() { if ($this->edit_mode) { $request = new UpdateDebiturRequest(); } else { $request = new StoreDebiturRequest(); } return $request->rules(); } }