'delete', 'update' => 'update', ]; public function render() { return view('writeoff::livewire.guarantee-type.guarantee-type-modal'); } protected function rules() { if ($this->edit_mode) { $request = new UpdateGuaranteeTypeRequest(); } else { $request = new StoreGuaranteeTypeRequest(); } return $request->rules(); } 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 $guarantee_type = GuaranteeType::find($this->id); $guarantee_type->update($data); $this->dispatch('success', __('Guarante Type updated')); } else { // Emit a success event with a message GuaranteeType::create($data); $this->dispatch('success', __('New Guarante Type created')); } }); // Reset the form fields after successful submission $this->reset(); } public function delete($id) { GuaranteeType::destroy($id); // Emit a success event with a message $this->dispatch('success', 'Guarante Type successfully deleted'); } public function update($id) { $this->edit_mode = true; $guarantee_type = GuaranteeType::find($id); $this->id = $guarantee_type->id; $this->kode = $guarantee_type->kode; $this->name = $guarantee_type->name; } public function hydrate() { $this->resetErrorBag(); $this->resetValidation(); } }