'delete', 'update' => 'update', ]; public function render() { $cabang = Branch::all(); $debitur = Debitur::all(); $product = Product::all(); $currency = Currency::all(); return view('writeoff::livewire.rekening.rekening-modal', compact([ 'cabang', 'debitur', 'product', 'currency' ])); } public function submit() { $this->validate(); // Validate the form input data DB::transaction(function () { // Prepare the data for creating a new user $data = [ 'nomor_rekening' => $this->nomor_rekening, 'branch_id' => $this->branch_id, 'debitur_id' => $this->debitur_id, 'product_id' => $this->product_id, 'currency_id' => $this->currency_id, 'status' => $this->status, 'status_rekening' => $this->status_rekening, 'limit_ref' => $this->limit_ref, 'registered_at' => $this->registered_at ]; if ($this->edit_mode) { // Emit a success event with a message $rekening = Rekening::find($this->id); $rekening->update($data); $this->dispatch('success', __('Rekening updated')); } else { // Emit a success event with a message Rekening::create($data); $this->dispatch('success', __('New Rekening created')); } }); // Reset the form fields after successful submission $this->reset(); } public function update($id) { $this->edit_mode = true; $rekening = Rekening::find($id); $this->id = $rekening->id; $this->nomor_rekening = $rekening->nomor_rekening; $this->branch_id = $rekening->branch_id; $this->debitur_id = $rekening->debitur_id; $this->product_id = $rekening->product_id; $this->currency_id = $rekening->currency_id; $this->status = $rekening->status == 1 ? true : false; $this->status_rekening = $rekening->status_rekening == 1 ? true : false; $this->limit_ref = $rekening->limit_ref; $this->registered_at = $rekening->registered_at; } public function delete($id) { Rekening::destroy($id); // Emit a success event with a message $this->dispatch('success', 'Rekening successfully deleted'); } public function hydrate() { $this->resetErrorBag(); $this->resetValidation(); } protected function rules() { if ($this->edit_mode) { $request = new UpdateRekeningRequest(); } else { $request = new StoreRekeningRequest(); } return $request->rules(); } }