'delete', 'update' => 'update', ]; public function render() { return view('writeoff::livewire.loan-type.loan-type-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 $loan_type = LoanType::find($this->id); $loan_type->update($data); $this->dispatch('success', __('Loan Type updated')); } else { // Emit a success event with a message LoanType::create($data); $this->dispatch('success', __('New Loan Type created')); } }); // Reset the form fields after successful submission $this->reset(); } public function update($id) { $this->edit_mode = true; $loan_type = LoanType::find($id); $this->id = $loan_type->id; $this->kode = $loan_type->kode; $this->name = $loan_type->name; } public function delete($id) { $loan = LoanType::find($id); $approval = [ 'method' => 'delete', 'menu' => 'Parameter Jenis Pinjaman', 'old_request' => json_encode($loan), 'description' => 'Delete Parameter Jenis Pinjaman', 'status' => '0', 'ref' => $loan->kode ]; $is_approval = Approval::where('menu', 'Parameter Jenis Pinjaman') ->where('ref', $loan->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 UpdateLoanTypeRequest(); } else { $request = new StoreLoanTypeRequest(); } return $request->rules(); } }