| 123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- namespace App\DTO;
- use App\Http\Requests\PermissionRequest;
- readonly class PermissionDTO
- {
- public function __construct(
- public string $scope,
- public string $description,
- public string $bits,
- public ?string $parent_id,
- ) {
- }
- public static function fromRequest(PermissionRequest $request): self
- {
- return new self(...$request->validated());
- }
- public function toArray(): array
- {
- return get_object_vars($this);
- }
- public static function fromArray(array $data): self
- {
- return new self(
- scope: $data['scope'],
- description: $data['description'],
- bits: $data['bits'],
- parent_id: isset($data['parent_id']) ? $data['parent_id'] : null,
- );
- }
- }
|