49 lines
1.2 KiB
PHP
49 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Data\Address;
|
|
|
|
use App\Contracts\OutputDataTransferObject;
|
|
use App\Models\Address;
|
|
|
|
final readonly class UserAddressResponseDTO implements OutputDataTransferObject
|
|
{
|
|
public function __construct(
|
|
public int $id,
|
|
public string $firstName,
|
|
public string $lastName,
|
|
public string $street,
|
|
public string $city,
|
|
public string $state,
|
|
public string $pinCode
|
|
) {}
|
|
|
|
public static function fromModel(Address $address): OutputDataTransferObject
|
|
{
|
|
return new self(
|
|
id: $address->id,
|
|
firstName: $address->first_name,
|
|
lastName: $address->last_name,
|
|
street: $address->street,
|
|
city: $address->city,
|
|
state: $address->state,
|
|
pinCode: $address->pin
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'firstName' => $this->firstName,
|
|
'lastName' => $this->lastName,
|
|
'street' => $this->street,
|
|
'city' => $this->city,
|
|
'state' => $this->state,
|
|
'pinCode' => $this->pinCode,
|
|
];
|
|
}
|
|
}
|