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

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

mohammedmanssour/super-simple-dto
=================================

Creating data transfer objects with the power of php objects

2.2.3(4mo ago)123.2k↑713.3%[2 PRs](https://github.com/mohammedmanssour/super-simple-dto/pulls)1MITPHPPHP ^8.1CI failing

Since May 28Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/mohammedmanssour/super-simple-dto)[ Packagist](https://packagist.org/packages/mohammedmanssour/super-simple-dto)[ Docs](https://github.com/mohammedmanssour/super-simple-dto)[ GitHub Sponsors](https://github.com/mohammedmanssour)[ RSS](/packages/mohammedmanssour-super-simple-dto/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (12)Versions (20)Used By (1)

Super Simple DTO
================

[](#super-simple-dto)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8eb3e905135bb895432d9fbb50833e0d826fb90fdb1fe90b816ee1ffad538af2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f68616d6d65646d616e73736f75722f73757065722d73696d706c652d64746f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mohammedmanssour/super-simple-dto)[![Tests](https://camo.githubusercontent.com/79e8f386f9f773d161cc5f8e6ca2f7dc1877759478e946d7723b59286db607a3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d6f68616d6d65646d616e73736f75722f73757065722d73696d706c652d64746f2f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/mohammedmanssour/super-simple-dto/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/4a01c35466a84f827d121779ff42e848bace87251f61cae2de1b9e9172483b44/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f68616d6d65646d616e73736f75722f73757065722d73696d706c652d64746f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mohammedmanssour/super-simple-dto)

Creating data transfer objects with the power of php objects. Simple, lightweight, and efficient DTO conversion with automatic type handling.

This is a laravel package and `laravel/framework` is part of the package dependencies. Please, make sure you have no problem with that before using.

Why Bother.
-----------

[](#why-bother)

The spatie team has already created an awesome package that serves as a [great solution for DTO objects](https://github.com/spatie/laravel-data/blob/main/composer.json). But, for me, it's full of features that I don't use and it seems like an overkill for me when I just wanted simple solution for DTO work.

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

[](#installation)

You can install the package via composer:

```
composer require mohammedmanssour/super-simple-dto
```

Usage
-----

[](#usage)

1. Apply the `AsDTO` trait to your data object

```
use MohammedManssour\DTO\Concerns\AsDTO;

class UserData
{
    use AsDTO;

    public string $name;
    public string $email;
    public BalanceData $balance;
    public Status $status;
}
```

2. Use one of these static methods to convert data into DTO:
    - `fromCollection`: converts collections to DTO objects.
    - `fromArray`: converts array to DTO objects.
    - `fromModel`: converts model to DTO objects. It works with the data available with `$model->getAttributes()` method.
    - `fromRequest`: converts laravel requests to DTO objects. It works with the data available with `validated()`. In case `validated` method is not available, it'll use the `all()` method. You can also force using request's `all` method by passing true as a second parameter.

```
UserData::fromCollection(collect([]));
UserData::fromArray([]);
UserData::fromModel($model);
UserData::fromRequest($request);
```

Features
--------

[](#features)

### Automatic Type Conversion

[](#automatic-type-conversion)

The package automatically handles type conversion for:

- **Enums**: Automatically converts values to enum instances
- **DTOs**: Automatically converts arrays/objects to other DTO instances
- **Built-in types**: Handles all PHP built-in types

### Array to DTO Collection Mapping with MapInto

[](#array-to-dto-collection-mapping-with-mapinto)

The `MapInto` attribute allows you to automatically convert arrays of data into arrays of DTO objects. This is particularly useful when working with collections of related data.

```
use MohammedManssour\DTO\Concerns\AsDTO;
use MohammedManssour\DTO\Support\MapInto;

class WalletData
{
    use AsDTO;

    public string $type;
    public int $balance;
}

class UserData
{
    use AsDTO;

    public string $name;
    public string $email;

    #[MapInto(WalletData::class)]
    public array $wallets;
}

$data = [
    'name' => 'Mohammed Manssour',
    'email' => 'hello@mohammedmanssour.me',
    'wallets' => [
        ['type' => 'bitcoin', 'balance' => 1000],
        ['type' => 'ethereum', 'balance' => 500],
    ]
];

$user = UserData::fromArray($data);

// $user->wallets will contain an array of WalletData objects
foreach ($user->wallets as $wallet) {
    echo $wallet->type . ': ' . $wallet->balance; // Each wallet is a WalletData instance
}
```

### Custom Property Setters

[](#custom-property-setters)

You can define custom setter methods for properties that need special handling:

```
class UserData
{
    use AsDTO;

    public Carbon $created_at;

    public function setCreatedAt($value)
    {
        $this->created_at = Carbon::parse($value);
    }
}
```

### Type Safety

[](#type-safety)

The package respects PHP type declarations and automatically converts:

```
class BalanceData
{
    use AsDTO;

    public float $bitcoin;
    public int $usdollar;
}

enum Status: string
{
    case Active = 'active';
    case Suspended = 'suspended';
}

class UserData
{
    use AsDTO;

    public BalanceData $balance;  // Automatically converted from array
    public Status $status;        // Automatically converted from string
}

$data = [
    'balance' => [
        'bitcoin' => 10.5,
        'usdollar' => 1000
    ],
    'status' => 'active'
];

$dto = UserData::fromArray($data);

// $dto->balance is a BalanceData instance
// $dto->status is a Status enum instance
```

Property Initialization Check
-----------------------------

[](#property-initialization-check)

The package provides a helpful `isset()` method that checks if a property was actually initialized (different from PHP's native `isset()` which returns false for `null` values):

```
$dto = UserData::fromArray([
    'name' => 'Mohammed',
    'email' => null  // explicitly set to null
]);

// Native PHP isset
isset($dto->name);     // true
isset($dto->email);    // false (because it's null)
isset($dto->balance);  // false (not initialized)

// DTO isset method
$dto->isset('name');     // true
$dto->isset('email');    // true (was explicitly set, even though null)
$dto->isset('balance');  // false (not initialized)
```

Converting DTO to Array
-----------------------

[](#converting-dto-to-array)

You can convert any DTO back to an array:

```
$dto = UserData::fromArray($data);
$array = $dto->toArray();
```

The `toArray()` method handles:

- Nested DTOs (converts them to arrays recursively)
- Enums (converts to their scalar values)
- Carbon instances (keeps as Carbon objects)
- Arrays of DTOs (converts each DTO to array)

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/master/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Mohammed Manssour](https://github.com/mohammedmanssour)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

48

—

FairBetter than 93% of packages

Maintenance78

Regular maintenance activity

Popularity27

Limited adoption so far

Community9

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

Recently: every ~30 days

Total

15

Last Release

122d ago

Major Versions

v1.6.0 → 2.0.02025-07-18

### Community

Maintainers

![](https://www.gravatar.com/avatar/aeb75f35979097845cce704062910a6a8c85bc0a7b49b081df7350a4f20023fc?d=identicon)[manssour.mohammed](/maintainers/manssour.mohammed)

---

Top Contributors

[![mohammedmanssour](https://avatars.githubusercontent.com/u/19733629?v=4)](https://github.com/mohammedmanssour "mohammedmanssour (21 commits)")

---

Tags

MohammedManssoursuper-simple-dto

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17878.9k](/packages/markwalet-nova-modal-response)[crumbls/layup

A visual page builder plugin for Filament 5 — Divi-style grid layouts with extensible widgets.

592.7k1](/packages/crumbls-layup)[team-nifty-gmbh/tall-datatables

Server-side rendered datatables for Laravel and Livewire

1320.9k4](/packages/team-nifty-gmbh-tall-datatables)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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