PHPackages                             hosseinkalateh/simple-dto - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hosseinkalateh/simple-dto

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hosseinkalateh/simple-dto
=========================

Data Transfer Objects in a simple way for Laravel applications

1.0.0(1y ago)47MITPHP

Since Oct 12Pushed 1y ago1 watchersCompare

[ Source](https://github.com/hosseinkalateh/simple-dto)[ Packagist](https://packagist.org/packages/hosseinkalateh/simple-dto)[ RSS](/packages/hosseinkalateh-simple-dto/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Simple-Dto
==========

[](#simple-dto)

DTOs (Data Transfer Objects) are objects that help facilitate the transfer of data between application layers, ensuring a structured and predictable format for the data being passed around.

Why Use DTOs?

Data Transfer Objects improve the separation of concerns by isolating data representation from the core business logic, making your code more maintainable and robust. They act as a layer between controllers, services, and models, providing more control over the data structure and improving security by limiting exposed data fields.

Features
--------

[](#features)

- Simplifies the creation and management of DTOs in Laravel.
- Enforces strict typing and validation of data.
- Integrates seamlessly into your Laravel projects without deviating from the framework's core conventions.
- Allowing form request validation fields to be derived automatically from the DTO properties, ensuring consistency and reducing duplication.

Installation
------------

[](#installation)

```
composer require hosseinkalateh/simple-dto
```

Usage
-----

[](#usage)

#### Creating a DTO

[](#creating-a-dto)

To create a new DTO class, you can use the following artisan command

```
php artisan make:dto UserDTO
```

This command will generate a new DTO class file in the app/DTO directory, ready for you to define the data structure.

You can define typed properties in your DTO outside the constructor:

```
final class UserDto
{
    public ?string $name;
    public string $first_name;
    public string $lastName;
    public string $SurName;
}

```

Remember that the property name convention can be whatever you want.

#### Creating a Form Request

[](#creating-a-form-request)

To create a new Form Request class, you can use the following artisan command

```
php artisan make:request-dto RegisterUserRequest --dto=UserDTO
```

In this command the --dto specifies the corresponding dto.

**NOTE :** --dto is required.

This command will generate a From Request file in the appropriate directory with the properties defined in the dto.

```
class RegisterUserRequest extends FormRequest
{
   public function rules()
    {
        return [
	    'name' => ['nullable'],
	    'first_name' => ['required'],
	    'last_name' => ['required'],
	    'sur_name' => ['required'],
	];
    }
}

```

#### Using DTO

[](#using-dto)

Now in the controller, you can access the request and the DTO also.

```
class UserController
{
    public function register(RegisterUserRequest $request)
    {
        $request->validated(); // Validated data just like the laravel core structure
        $request->toDto();     // Will return the dto instance
    }
}

```

**NOTE :** $request-&gt;toDto() will return the DTO instance that we passed to the make request command.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

578d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/772328f42c631e19085ce5bde76e7b45dcbb56c34f1694d97c8f208022627c81?d=identicon)[hossein\_kalateh](/maintainers/hossein_kalateh)

---

Top Contributors

[![hosseinkalateh](https://avatars.githubusercontent.com/u/59473049?v=4)](https://github.com/hosseinkalateh "hosseinkalateh (4 commits)")

---

Tags

laraveldata-transfer-objectdto

### Embed Badge

![Health badge](/badges/hosseinkalateh-simple-dto/health.svg)

```
[![Health](https://phpackages.com/badges/hosseinkalateh-simple-dto/health.svg)](https://phpackages.com/packages/hosseinkalateh-simple-dto)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
