PHPackages                             bpartner/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. bpartner/dto

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

bpartner/dto
============

DTO with simple factory

1.1.11(3y ago)01.4kMITPHPPHP ^8.0

Since Mar 8Pushed 3y ago1 watchersCompare

[ Source](https://github.com/bpartner/dto)[ Packagist](https://packagist.org/packages/bpartner/dto)[ Docs](https://github.com/bpartner/dto)[ RSS](/packages/bpartner-dto/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (3)Versions (15)Used By (0)

Laravel Data transfer objects helper
====================================

[](#laravel-data-transfer-objects-helper)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8345e39e82149dc41adc0ea04af049ae4b3b746b478b8d2d7014cc860fe0fb0b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62706172746e65722f64746f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bpartner/dto)[![Total Downloads](https://camo.githubusercontent.com/f8420857cc3250b1b466dd280557ea278b36379863972f1e013ed8698f6adabe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62706172746e65722f64746f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bpartner/dto)

Simple create DTO from any array.

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

[](#installation)

\####Requirements:

- PHP 8.0
- Laravel 8 | 9

You can install the package via composer:

```
composer require bpartner/dto
```

Usage
-----

[](#usage)

Declare you DTO object. You can use any types declarations.

For array or collection you can use PHPDoc annotation with type of data inside. Supported only array and collection.

```
class DemoDto extends DtoAbstract
{
    //Optional
    protected const CLASS_FORM_REQUEST = UpdateUserFormRequest::class;

    /**
    * DTO fields
    */
    public string $name;
    public Carbon $date;
    public DtoOtherObject $otherObject;

    /** @var collection  */
    public Collection $objectsCollection;

    /** @var array  */
    public array $objectsArray;

    /** @var collection  */
    public array $objectsArrayOfCollection;
    }
```

Create DTO from any array data (example: request()-&gt;all()) by facade Dto

```
//In any place of your code
$data = request()->all(); //array data
$dto = Dto::build(DemoDto::class, $data);
```

or from FormRequest

```
/**
 * In controller
 *
 * Create FormRequest and assign to CLASS_FORM_REQUEST const in DTO
 *
 */
public function store(DemoDto $dto)
{
    //Use $dto made from UpdateUserFormRequest
}
```

Now you can transfer your DTO to any Object as parameter and use:

```
$name = $dto->name;
$objectCollection = $dto->objectsCollection;
```

You can transform input parameters to any string format by third parameter. (example: first\_name -&gt; firstName)

```
class DemoDto extends DtoAbstract
{
    public string $firstName;
}

$inputData = [
    'first_name' => 'John Doe'
];

$dto = Dto::build(DemoDto::class, $inputData, DtoFactory::CAMEL_CASE);
```

### Custom mapping

[](#custom-mapping)

You can create DTO with custom mapping. Add static method withMap()

```
public static function withMap(array $data): DtoInterface
{
    $mappedData = [
        'dto_param' => $data['some_param'],
    ];

    return new static($mappedData);
}

//Client code
$dto = Dto::build(DemoDto::class, request()->all());
```

Transform your DTO to array or flat array.

```
$array = $dto->toArray();

array:4 [
  "name" => "Demo data"
  "date" => "06-11-2021"
  "phone" => array:2 [
    "type" => "home"
    "number" => "500-123-123"
  ]
  "phones" => array:2 [
    0 => array:2 [
      "type" => "work"
      "number" => "500-123-122"
    ]
    1 => array:2 [
      "type" => "private"
      "number" => "500-123-124"
    ]
  ]
]

$flat = $dto->flatArray();

array:5 [
  "name" => "Demo data"
  "date" => "06-11-2021"
  "type" => "home"
  "number" => "500-123-123"
  "phones" => array:2 [
    0 => array:2 [
      "type" => "work"
      "number" => "500-123-122"
    ]
    1 => array:2 [
      "type" => "private"
      "number" => "500-123-124"
    ]
  ]
]
```

Important! Collections and nested arrays are not flip to flat array.

Credits
-------

[](#credits)

- [Alexander Zinchenko](https://github.com/bpartner)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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

Every ~39 days

Total

13

Last Release

1107d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/41556cf93fd356db054066226b59fd32e9c20686db7de5cdc689dc204e5d7208?d=identicon)[bpartner](/maintainers/bpartner)

---

Top Contributors

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

---

Tags

dtobpartner

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[illuminate/pagination

The Illuminate Pagination package.

12234.1M1.0k](/packages/illuminate-pagination)[illuminate/pipeline

The Illuminate Pipeline package.

9349.2M282](/packages/illuminate-pipeline)[illuminate/redis

The Illuminate Redis package.

8314.6M376](/packages/illuminate-redis)[illuminate/cookie

The Illuminate Cookie package.

244.6M137](/packages/illuminate-cookie)

PHPackages © 2026

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