AuthDTO.php 769 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\DTO;
  3. use App\Http\Requests\AuthRequest;
  4. readonly class AuthDTO
  5. {
  6. public function __construct(
  7. public string $email,
  8. public string $password,
  9. ) {
  10. }
  11. public static function fromRequest(AuthRequest $request): self
  12. {
  13. return new self(
  14. email: $request->validated(key: 'email'),
  15. password: $request->validated(key: 'password'),
  16. );
  17. }
  18. public function toArray(): array
  19. {
  20. return [
  21. 'email' => $this->email,
  22. 'password' => $this->password,
  23. ];
  24. }
  25. public static function fromArray(array $data): self
  26. {
  27. return new self(
  28. email: $data['email'],
  29. password: $data['password'],
  30. );
  31. }
  32. }