{"id":20796691,"url":"https://github.com/gotocva/dto-in-laravel","last_synced_at":"2026-04-04T03:34:14.652Z","repository":{"id":114647164,"uuid":"337932037","full_name":"gotocva/DTO-in-laravel","owner":"gotocva","description":null,"archived":false,"fork":false,"pushed_at":"2021-02-11T04:51:43.000Z","size":1,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-18T11:29:12.881Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gotocva.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-11T04:48:03.000Z","updated_at":"2021-02-11T04:51:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"0a045c59-9c76-4b6d-bbcf-f92d7ea2d480","html_url":"https://github.com/gotocva/DTO-in-laravel","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotocva%2FDTO-in-laravel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotocva%2FDTO-in-laravel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotocva%2FDTO-in-laravel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotocva%2FDTO-in-laravel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gotocva","download_url":"https://codeload.github.com/gotocva/DTO-in-laravel/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243141256,"owners_count":20242817,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T16:28:39.005Z","updated_at":"2025-12-27T06:34:48.713Z","avatar_url":"https://github.com/gotocva.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# DTO-in-laravel\n\nData Transfer Objects help in \"structuring\" the data coming from different types of requests ( Http request, Webhook request etc. ) into single form which we can use in various parts of our application. With DTOs, we have confidence that we will not get unexpected data in our application logic.\n\n```\nNOTE: Below code is valid only for PHP 7.4\n```\n\n```php\nclass CheckoutData extends DataTransferObject\n{\n\n   public int $checkout_id;\n\n   public Carbon $completed_at;\n\n\n   public static function fromRequest(Request $request){ ... }\n\n   public static function fromWebhook(array $params)\n\n   {\n\n      return new self([\n        'checkout_id' =\u003e $params['id'],\n        'completed_at' =\u003e $params['completed_at']\n      ]);\n\n   }\n\n}\n```\n\n```php\n\nabstract class DataTransferObject\n{\n\n    public function __construct(array $parameters = [])\n    {\n        $class = new ReflectionClass(static::class);\n\n        foreach ($class-\u003egetProperties(ReflectionProperty::IS_PUBLIC) as $reflectionProperty){\n            $property = $reflectionProperty-\u003egetName();\n            $this-\u003e{$property} = $parameters[$property];\n        }\n    }\n\n}\n\n```\n\nThis is how we can easily construct our Data Transfer Objects with PHP7.4.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgotocva%2Fdto-in-laravel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgotocva%2Fdto-in-laravel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgotocva%2Fdto-in-laravel/lists"}