Created
November 11, 2024 05:07
-
-
Save alfaz86/993a7313c6445dd23f0db13cafde4125 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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