form->validate(); $startDate = CarbonImmutable::parse($this->form->date_start); $endDate = CarbonImmutable::parse($this->form->date_end); if ($this->mode === 'create') { $create->execute(new InitializeAcademicTermDTO( name: $this->form->name, code: $this->form->code, yearStudy: $this->form->year_study, semester: $this->form->semester, startDate: $startDate, endDate: $endDate, )); } elseif ($this->mode === 'update') { $update->execute($this->term, new ModifyTermDateDTO( startDate: $startDate, endDate: $endDate, )); } $this->success($this->message); $this->dispatch('hide-term-form-modal'); $this->js("LaravelDataTables['term-table'].ajax.reload(null, false)"); $this->form->reset(); $this->form->resetValidation(); $this->reset('id', 'mode'); } #[Computed] public function term(): ?Term { return $this->id ? Term::where('ulid', $this->id)->first() : null; } public function show(int|string $id): void { $this->id = $id; $this->mode = 'update'; $this->form->fill($this->term->only(['name', 'code', 'year_study', 'semester'])); $this->form->date_start = $this->term->date_start->format('Y-m-d'); $this->form->date_end = $this->term->date_end->format('Y-m-d'); } public function hide(): void { $this->form->reset(); $this->form->resetValidation(); $this->reset('id', 'mode'); } };