authorize('customers.use'); $summary = $customerQueries->findSummary($customer); abort_if($summary === null, 404); $this->customerId = $summary->id; $this->customerName = $summary->name; if ($contact === null) { return; } $contactSummary = $customerQueries->findContact($customer, $contact); abort_if($contactSummary === null, 404); $this->contactId = $contactSummary->id; $this->form->fillFromSummary($contactSummary); } public function save(AddContact $addContact, UpdateContact $updateContact): void { $this->authorize('customers.use'); $data = $this->form->toData(); try { if ($this->contactId === null) { $addContact->execute($this->customerId, $data); session()->flash('status', __('customers.contacts.created', ['name' => $data->name])); } else { $updateContact->execute($this->customerId, $this->contactId, $data); session()->flash('status', __('customers.contacts.updated', ['name' => $data->name])); } } catch (CustomerNotFound|ContactNotFound) { abort(404); } catch (DomainException $exception) { $this->form->showDomainError($exception); return; } $this->redirectRoute('customers.show', $this->customerId, navigate: true); } public function render(): mixed { return $this->view()->title($this->heading().' – '.$this->customerName); } public function heading(): string { return __($this->contactId === null ? 'customers.contacts.create_title' : 'customers.contacts.edit_title'); } }; ?>
{{ $this->heading() }}

{{ __('customers.customer_label') }}: {{ $customerName }}