Skip to content

Instantly share code, notes, and snippets.

@alfaz86
Created November 11, 2024 05:07
Show Gist options
  • Save alfaz86/993a7313c6445dd23f0db13cafde4125 to your computer and use it in GitHub Desktop.
Save alfaz86/993a7313c6445dd23f0db13cafde4125 to your computer and use it in GitHub Desktop.
<?php
namespace App\DTOs;
class UserDTO
{
public string $name;
public string $email;
public string $role;
public ?string $address;
public ?string $phoneNumber;
public function __construct(
string $name,
string $email,
string $role,
?string $address = null,
?string $phoneNumber = null
) {
$this->name = $name;
$this->email = $email;
$this->role = $role;
$this->address = $address;
$this->phoneNumber = $phoneNumber;
}
public static function fromRequest($request): self
{
return new self(
name: $request->get('name'),
email: $request->get('email'),
role: $request->get('role'),
address: $request->get('address'),
phoneNumber: $request->get('phoneNumber')
);
}
public function toArray(): array
{
return [
'name' => $this->name,
'email' => $this->email,
'role' => $this->role,
'address' => $this->address,
'phoneNumber' => $this->phoneNumber,
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment