where('customer_id', $customerId)->find($contactId); return $model === null ? null : $this->toEntity($model); } public function save(CustomerContact $contact): CustomerContact { $model = $contact->id() === null ? new CustomerContactModel : CustomerContactModel::query()->findOrFail($contact->id()); $model->fill([ 'customer_id' => $contact->customerId(), 'name' => $contact->name()->value, 'title' => $contact->title(), 'phone' => $contact->phone(), 'email' => $contact->email()?->value, 'note' => $contact->note(), ])->save(); return $this->toEntity($model); } public function delete(CustomerContact $contact): void { CustomerContactModel::query()->whereKey($contact->id())->delete(); } private function toEntity(CustomerContactModel $model): CustomerContact { return CustomerContact::reconstitute( $model->id, $model->customer_id, new ContactName($model->name), $model->title, $model->phone, $model->email === null ? null : new EmailAddress($model->email), $model->note, ); } }