', $props); $this->{$props} = $value; $coa = $this->chartOfAccounts->where('ulid', $value)->first(); if ($coa) { $this->form->code = $coa->code + 1; $this->form->classification = $coa->classification; } } } public function show(int|string $id): void { $this->id = $id; $this->mode = 'update'; $coa = $this->coa->only(['name', 'code', 'classification', 'status', 'parent_id']); $coa['parent_id'] = $this->chartOfAccounts ->where('id', $coa['parent_id']) ->first() ?->ulid; $this->form->fill($coa); } #[Computed] public function coa(): ChartOfAccount { return $this->id ? ChartOfAccount::where('ulid', $this->id)->first() : new ChartOfAccount; } #[Computed] public function chartOfAccounts(): Collection { return ChartOfAccount::query() ->select(['id', 'name', 'code', 'ulid', 'classification']) ->get(); } public function save(RegisterChartOfAccount $register, AdjustAccountClassification $adjust): void { $this->form->validate(); $parentId = $this->chartOfAccounts ->where('ulid', $this->form->parent_id) ->first() ->id; if ($this->mode === 'create') { $register->execute(new RegisterChartOfAccountDTO( code: $this->form->code, name: $this->form->name, classification: $this->form->classification, status: $this->form->status, parentId: $parentId, )); } elseif ($this->mode == 'update') { $adjust->execute($this->coa, new AdjustAccountClassificationDTO( code: $this->form->code, classification: $this->form->classification, parentId: $parentId, )); } $this->dispatch('hide-chartofaccount-form-modal'); $this->js("LaravelDataTables['chartofaccount-table'].ajax.reload(null, false)"); } public function hide(): void { $this->form->reset(); $this->reset('id', 'mode'); } };