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

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

jnariai/simple-dto
==================

A simple data transfer object for Laravel

1.0.0(1y ago)04MITPHPPHP ^8.2CI passing

Since Mar 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/jnariai/simple-dto)[ Packagist](https://packagist.org/packages/jnariai/simple-dto)[ Docs](https://github.com/jnariai/simple-dto)[ GitHub Sponsors](https://github.com/SimpleDTO)[ RSS](/packages/jnariai-simple-dto/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (13)Versions (2)Used By (0)

Simple DTO
==========

[](#simple-dto)

Immutable Data Transfer Object (DTO) for PHP inspired by [Laravel Data](https://github.com/spatie/laravel-data) and [Bags](https://github.com/dshafik/bag)

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

[](#introduction)

This is a package to create minimal immutable Data Transfer Object for PHP with some handy features like the method from to create the dto from array, it implements `Arrayable` and `Jsonable` interfaces, and also has two attributes to use `#[NonNullOutput]` and `#[Hidden]` to help in the output transformation.

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

[](#installation)

You can install the package via composer:

```
composer require jnariai/simple-dto
```

Usage
-----

[](#usage)

```
use SimpleDTO\DTO;

final readonly class MyDTO extends DTO
{
    public function __construct(
        public bool $property_bool,
        public ?string $property_string,
        public string $sensitive_data,
    ) {}
}
```

You can create the DTO using the static function `from::` and pass an array of data

```
$myDTO = MyDTO::from([
    'property_bool' => true,
    'sensitive_data' => 'sensitive data',
]);

// You don't need to pass properties that can be null, it will automatically be set to null
/* MyDTO {
  +property_bool: true
  +property_string: null
  +sensitive_data: "sensitive data"
}
*/
```

You can also get a toArray an toJson method

```
$myDTO->toArray(); // ['property_bool' => true, 'property_string' => null, 'sensitive_data' => 'sensitive data']
$myDTO->toJson(); // {"property_bool":true,"property_string":null,"sensitive_data":"sensitive data"}
```

You also get two available attributes to use. `#[NonNullOutput]` and `#[Hidden]`.

`#[NonNullOutput]` is a class Attribute and when using toArray or toJson it will only return properties that are not null.

```
use SimpleDTO\DTO;

#[NonNullOutput]
final readonly class MyDTO extends DTO
{
    public function __construct(
        public bool $property_bool,
        public ?string $property_string,
        public string $sensitive_data,
    ) {}
}

$myDTO->toArray(); // ['property_bool' => true, 'sensitive_data' => 'sensitive data']
$myDTO->toJson(); // {"property_bool":true,"sensitive_data":"sensitive data"}
```

`#[Hidden]` is a property Attribute and when using toArray or toJson it will not return the property.

```
use SimpleDTO\DTO;

final readonly class MyDTO extends DTO
{
    public function __construct(
    public bool $property_bool,
    public ?string $property_string,
    #[Hidden]
    public string $sensitive_data,
    ) {}
}

$myDTO->toArray(); // ['property_bool' => true, 'property_string' => null]
$myDTO->toJson(); // {"property_bool":true,"property_string":null}
```

License
-------

[](#license)

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

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance45

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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

Unknown

Total

1

Last Release

426d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4114ff504446783b8eaf662653c527ab7ce8f66c244a7b64fe1e1a10a77da0fe?d=identicon)[jnariai](/maintainers/jnariai)

---

Top Contributors

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

---

Tags

laravelSimpleDTOsimple-dto

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M626](/packages/spatie-laravel-data)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)

PHPackages © 2026

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