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

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

benycode/dto
============

data transfer object representation based on laravel validation

v1.0.3(5y ago)119MITPHPPHP ^7.4

Since Mar 15Pushed 5y ago1 watchersCompare

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

READMEChangelog (4)Dependencies (5)Versions (5)Used By (0)

Laravel DTO
===========

[](#laravel-dto)

[![Build Status](https://camo.githubusercontent.com/bbe8adadd7c8a7b02c530f4fb150127bd96425bc61d2888b505a880c39f05a3f/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f62656e79636f64652f64746f2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/benycode/dto)[![Latest Stable Version](https://camo.githubusercontent.com/b1c52c456370c0842e5a2f39cb56ab3b9799d91cdffc35e26b90f574f94a0ef5/68747470733a2f2f706f7365722e707567782e6f72672f62656e79636f64652f64746f2f762f737461626c65)](https://packagist.org/packages/benycode/dto)[![Total Downloads](https://camo.githubusercontent.com/ddc4dcef8e1e4a1c32e33ccc93cd633ab5d18e3b9bcd82278dd8fb17d16011ba/68747470733a2f2f706f7365722e707567782e6f72672f62656e79636f64652f64746f2f646f776e6c6f616473)](https://packagist.org/packages/benycode/dto)[![License](https://camo.githubusercontent.com/949a987a15836600443207a20a421e5bf5bcbc895dae629ef2e32478c9344ae5/68747470733a2f2f706f7365722e707567782e6f72672f62656e79636f64652f64746f2f6c6963656e7365)](https://packagist.org/packages/benycode/dto)

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

[](#installation)

You can install the package via composer:

```
composer require benycode/dto
```

Introduction
------------

[](#introduction)

Working with arrays is painfully. This package represents simple trait that can makes your life easier. It gives you an ability to convert arrays to Data Transfer Objects and validates it using laravel validator facade.

Here are a couple of examples:

```
class UserDTO implements Arrayable, JsonSerializable
{
    use DTOTrait;

    /**
     * @var int
     */
    private $id;

    /**
     * @var string
     */
    private $name;

    /**
     * @var string
     */
    private $avatarUrl;

    /**
     * UserDTO constructor.
     * @param int $id
     * @param string $name
     * @param string $avatarUrl
     */
    public function __construct(int $id, string $name, string $avatarUrl)
    {
        $this->id = $id;
        $this->name = $name;
        $this->avatarUrl = $avatarUrl;
    }

    /**
     * @return int
     */
    public function getId(): int
    {
        return $this->id;
    }

    /**
     * @return string
     */
    public function getName(): string
    {
        return $this->name;
    }

    /**
     * @return string
     */
    public function getAvatarUrl(): string
    {
        return $this->avatarUrl;
    }

    /**
     * @inheritDoc
     */
    protected static function createFromArray(array $data): self
    {
        return new self(
            Arr::get($data, 'id'),
            Arr::get($data, 'name'),
            Arr::get($data, 'avatar_url')
        );
    }

    /**
     * @return array
     */
    protected static function validationRules(): array
    {
        return [
            'id' => 'required|integer',
            'name' => 'required|string|max:255',
            'avatar_url' => 'required|string|url',
        ];
    }

    /**
     * @return array
     */
    public function toArray(): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'avatar_url' => $this->avatarUrl
        ];
    }

    /**
     * @inheritDoc
     */
    public function jsonSerialize(): array
    {
        return $this->toArray();
    }
}
```

Then you can easily do:

```
    try {
        $dto = UserDTO::fromArray([
            'id' => 1,
            'name' => 'Alex',
            'avatar_url' => 'http://google.com'
        ]);

        dd($dto->toArray(), json_encode($dto));
    } catch (ValidationException $exception) {
        dd($exception->errors());
    }
```

Samples
-------

[](#samples)

Samples can be found in `/tests/Unit/Samples`

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 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 ~0 days

Total

4

Last Release

1887d ago

PHP version history (2 changes)v1.0.0PHP ^7.2

v1.0.3PHP ^7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/cb3e8d371d500a222cf7d259a737b7de87389296eb9584360f9a68c594d2a2dc?d=identicon)[benycode](/maintainers/benycode)

---

Top Contributors

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

---

Tags

laraveldtoBenyCode

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[tonysm/importmap-laravel

Use ESM with importmap to manage modern JavaScript in Laravel without transpiling or bundling.

148399.8k1](/packages/tonysm-importmap-laravel)[bensampo/laravel-embed

Painless responsive embeds for videos, slideshows and more.

142146.8k](/packages/bensampo-laravel-embed)[dragon-code/pretty-routes

Pretty Routes for Laravel

10058.7k4](/packages/dragon-code-pretty-routes)[laracraft-tech/laravel-useful-additions

A collection of useful Laravel additions!

58109.4k](/packages/laracraft-tech-laravel-useful-additions)[watson/nameable

Format names of users into full, familiar and abbreviated forms

299.7k](/packages/watson-nameable)

PHPackages © 2026

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