PHPackages                             kryptamine/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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. kryptamine/dto

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

kryptamine/dto
==============

data transfer object representation based on laravel validation

1.0.0(6y ago)47MITPHPPHP ^7.2CI failing

Since Feb 1Pushed 6y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (5)Versions (3)Used By (0)

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

[](#laravel-dto)

[![Build Status](https://camo.githubusercontent.com/4f55044e13c7e7a40e071358bfe6a1941b918205842525c5ff09427fb87bc8a8/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6b72797074616d696e652f64746f2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/kryptamine/dto)[![Latest Stable Version](https://camo.githubusercontent.com/6a728b0dda43206e3eefee24105810e46e21ab908658943d52bb55ceb35b386e/68747470733a2f2f706f7365722e707567782e6f72672f6b72797074616d696e652f64746f2f762f737461626c65)](https://packagist.org/packages/kryptamine/dto)[![Total Downloads](https://camo.githubusercontent.com/ae7228712ad864f64561419eb1014f4127123295cd7b1799cd012f871f74ef00/68747470733a2f2f706f7365722e707567782e6f72672f6b72797074616d696e652f64746f2f646f776e6c6f616473)](https://packagist.org/packages/kryptamine/dto)[![License](https://camo.githubusercontent.com/e3d0e4b3b131a4cfa3af577ceb76b6ebd3da063cd29b84210b360ad761b362ad/68747470733a2f2f706f7365722e707567782e6f72672f6b72797074616d696e652f64746f2f6c6963656e7365)](https://packagist.org/packages/kryptamine/dto)

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

[](#installation)

You can install the package via composer:

```
composer require kryptamine/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

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

2

Last Release

2343d ago

Major Versions

0.0.1 → 1.0.02020-02-01

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7682795?v=4)[Alexander Satretdinov](/maintainers/kryptamine)[@kryptamine](https://github.com/kryptamine)

---

Top Contributors

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

---

Tags

dtolaravellaravel-packagelaraveldtokryptamine

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

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

Dashboard and code-driven configuration for Laravel queues.

4.2k95.4M302](/packages/laravel-horizon)[laravel/sail

Docker files for running a basic Laravel application.

1.9k205.7M1.3k](/packages/laravel-sail)[illuminate/database

The Illuminate Database package.

2.8k54.9M11.6k](/packages/illuminate-database)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M193](/packages/laravel-ai)[moonshine/moonshine

Laravel administration panel

1.3k253.1k81](/packages/moonshine-moonshine)

PHPackages © 2026

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