Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ClientDTO.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\DTO;
  3. use App\Models\Common\Client;
  4. readonly class ClientDTO
  5. {
  6. public function __construct(
  7. public string $name,
  8. public string $addressLine1,
  9. public string $addressLine2,
  10. public string $city,
  11. public string $state,
  12. public string $postalCode,
  13. public string $country,
  14. ) {}
  15. public static function fromModel(Client $client): self
  16. {
  17. $address = $client->billingAddress ?? null;
  18. return new self(
  19. name: $client->name,
  20. addressLine1: $address?->address_line_1 ?? '',
  21. addressLine2: $address?->address_line_2 ?? '',
  22. city: $address?->city ?? '',
  23. state: $address?->state?->name ?? '',
  24. postalCode: $address?->postal_code ?? '',
  25. country: $address?->country?->name ?? '',
  26. );
  27. }
  28. public function getFormattedAddressHtml(): ?string
  29. {
  30. if (empty($this->addressLine1)) {
  31. return null;
  32. }
  33. $lines = array_filter([
  34. $this->addressLine1,
  35. $this->addressLine2,
  36. implode(', ', array_filter([
  37. $this->city,
  38. $this->state,
  39. $this->postalCode,
  40. ])),
  41. $this->country,
  42. ]);
  43. return collect($lines)
  44. ->map(static fn ($line) => "<p>{$line}</p>")
  45. ->join('');
  46. }
  47. }