You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CompanyDTO.php 740B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace App\DTO;
  3. use App\Models\Company;
  4. readonly class CompanyDTO
  5. {
  6. public function __construct(
  7. public string $name,
  8. public string $address,
  9. public string $city,
  10. public string $state,
  11. public string $zipCode,
  12. public string $country,
  13. ) {}
  14. public static function fromModel(Company $company): self
  15. {
  16. $profile = $company->profile;
  17. return new self(
  18. name: $company->name,
  19. address: $profile->address ?? '',
  20. city: $profile->city?->name ?? '',
  21. state: $profile->state?->name ?? '',
  22. zipCode: $profile->zip_code ?? '',
  23. country: $profile->state?->country->name ?? '',
  24. );
  25. }
  26. }