PHPackages                             juststeveking/laravel-data-object-tools - 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. juststeveking/laravel-data-object-tools

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

juststeveking/laravel-data-object-tools
=======================================

A set of tools to make working with Data Transfer Objects easier in Laravel

2.0.0(1y ago)6714.3k↓50%9[1 PRs](https://github.com/JustSteveKing/laravel-data-object-tools/pulls)3MITPHPPHP ^8.1CI passing

Since Jul 28Pushed 1y ago2 watchersCompare

[ Source](https://github.com/JustSteveKing/laravel-data-object-tools)[ Packagist](https://packagist.org/packages/juststeveking/laravel-data-object-tools)[ RSS](/packages/juststeveking-laravel-data-object-tools/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (7)Versions (5)Used By (3)

Laravel Data Object Tools
=========================

[](#laravel-data-object-tools)

[![Latest Version](https://camo.githubusercontent.com/dd38c86b17e4247a8a743f6887aa0f9b779e386ff414325a76b4b31fe45026c2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a75737473746576656b696e672f6c61726176656c2d646174612d6f626a6563742d746f6f6c732e7376673f7374796c653d666c61742d737175617265266c6162656c3d72656c65617365)](https://packagist.org/packages/juststeveking/laravel-data-object-tools)[![PHP Version](https://camo.githubusercontent.com/283161e9bc5a0b210041e8e33a609ddae6d6399806804c287cbf7b118bbaade7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6a75737473746576656b696e672f6c61726176656c2d646174612d6f626a6563742d746f6f6c732e7376673f7374796c653d666c61742d737175617265)](https://php.net)[![Tests](https://github.com/juststeveking/laravel-data-object-tools/actions/workflows/test.yml/badge.svg)](https://github.com/juststeveking/laravel-data-object-tools/actions/workflows/test.yml)[![Total Downloads](https://camo.githubusercontent.com/66c1226a2a5d383756505ee679e0dff49aa240639cf5a7df89bbe383106343be/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a75737473746576656b696e672f6c61726176656c2d646174612d6f626a6563742d746f6f6c732e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d6d656469756d76696f6c6574726564)](https://packagist.org/packages/juststeveking/laravel-data-object-tools)

This package is aimed to be a suite of tools to help working with DTOs even easier. It includes an artisan command to generate DTOs as well as a facade to help you hydrate them.

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

[](#installation)

```
composer require juststeveking/laravel-data-object-tools
```

Usage
-----

[](#usage)

To generate a new DTO all you need to do is run the following artisan command:

```
php artisan make:dto MyDto
```

This will generate the following class: `app/DataObjects/MyDto.php`. By default this class will be a `final` class that implements a `DataObjectContract` which enforces a method `toArray` so that you can easily cast your DTOs to arrays.

If you are using PHP 8.2 however, you will by default get a `readonly` class generated, so that you do not have to declare each property as readonly.

To work with the hydration functionality you can either use Laravels DI container, or the ready made facade.

Using the container:

```
class StoreController
{
    public function __construct(
        private readonly HydratorContract $hydrator,
    ) {}

    public function __invoke(StoreRequest $request)
    {
        $model = Model::query()->create(
            attributes: $this->hydrator->fill(
                class: ModelObject::class,
                parameters: $request->validated(),
            )->toArray(),
        );
    }
}
```

To work with the facade, you can do something very similar:

```
class StoreController
{
    public function __invoke(StoreRequest $request)
    {
        $model = Model::query()->create(
            attributes: Hydrator::fill(
                class: ModelObject::class,
                parameters: $request->validated(),
            )->toArray(),
        );
    }
}
```

Object Hydration
----------------

[](#object-hydration)

Under the hood this package uses an [EventSauce](https://eventsauce.io) package, created by [Frank de Jonge](https://twitter.com/frankdejonge). It is possibly the best package I have found to hydrate objects nicely in PHP. You can find the [documentation here](https://github.com/EventSaucePHP/ObjectHydrator)if you would like to see what else you are able to do with the package to suit your needs.

Testing
-------

[](#testing)

To run the test suite:

```
composer run test
```

Credits
-------

[](#credits)

- [Steve McDougall](https://github.com/JustSteveKing)
- [All Contributors](../../contributors)

LICENSE
-------

[](#license)

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

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 76.5% 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 ~258 days

Total

4

Last Release

607d ago

Major Versions

1.1.0 → 2.0.02024-09-10

### Community

Maintainers

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

---

Top Contributors

[![JustSteveKing](https://avatars.githubusercontent.com/u/6368379?v=4)](https://github.com/JustSteveKing "JustSteveKing (13 commits)")[![ludoguenet](https://avatars.githubusercontent.com/u/36139526?v=4)](https://github.com/ludoguenet "ludoguenet (2 commits)")[![frankdejonge](https://avatars.githubusercontent.com/u/534693?v=4)](https://github.com/frankdejonge "frankdejonge (1 commits)")[![YOzaz](https://avatars.githubusercontent.com/u/5859318?v=4)](https://github.com/YOzaz "YOzaz (1 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/juststeveking-laravel-data-object-tools/health.svg)

```
[![Health](https://phpackages.com/badges/juststeveking-laravel-data-object-tools/health.svg)](https://phpackages.com/packages/juststeveking-laravel-data-object-tools)
```

###  Alternatives

[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M210](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M858](/packages/illuminate-pagination)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[illuminate/broadcasting

The Illuminate Broadcasting package.

7126.5M177](/packages/illuminate-broadcasting)[illuminate/redis

The Illuminate Redis package.

8314.0M314](/packages/illuminate-redis)[bensampo/laravel-embed

Painless responsive embeds for videos, slideshows and more.

142146.8k](/packages/bensampo-laravel-embed)

PHPackages © 2026

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