*/ final readonly class ShopDto implements Arrayable, UrlRoutable { /** * @param \Illuminate\Support\Collection|null $pickupExceptions */ public function __construct( public string $id, public string $name, public string $address, public string $postcode, public string $city, public ?string $phone, public ?string $latitude, public ?string $longitude, public bool $default, public ?Collection $pickupExceptions = null, ) { } public static function fromModel(Shop $shop): self { $pickupExceptions = null; if ($shop->relationLoaded('pickupExceptions')) { $pickupExceptions = $shop->pickupExceptions->map( fn (PickupException $pe): PickupExceptionDto => PickupExceptionDto::fromModel($pe) ); } return new self( id: $shop->id, name: $shop->name, address: $shop->address, postcode: $shop->postcode, city: $shop->city, phone: $shop->phone, latitude: $shop->latitude, longitude: $shop->longitude, default: (bool) $shop->default, pickupExceptions: $pickupExceptions, ); } public static function fromDomain(DomainShop $shop): self { return new self( id: $shop->id->value->toString(), name: $shop->name, address: $shop->address, postcode: $shop->postcode, city: $shop->city, phone: $shop->phone, latitude: $shop->latitude, longitude: $shop->longitude, default: $shop->isDefault, ); } #[\Override] public function getRouteKey(): mixed { return $this->id; } #[\Override] public function getRouteKeyName(): string { return 'id'; } #[\Override] public function resolveRouteBinding($value, $field = null): mixed { return null; } #[\Override] public function resolveChildRouteBinding($childType, $value, $field): mixed { return null; } /** * @return array */ #[\Override] public function toArray(): array { return [ 'id' => $this->id, 'name' => $this->name, 'address' => $this->address, 'postcode' => $this->postcode, 'city' => $this->city, 'phone' => $this->phone, 'latitude' => $this->latitude, 'longitude' => $this->longitude, 'default' => $this->default, ]; } }