PHPackages                             nandan108/dto-toolkit-laravel - 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. nandan108/dto-toolkit-laravel

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

nandan108/dto-toolkit-laravel
=============================

Laravel adapter for DTO Toolkit (DTOT)

v0.1.0(2mo ago)00MITPHPPHP &gt;=8.1.31 &lt;8.6CI passing

Since Feb 23Pushed 2mo agoCompare

[ Source](https://github.com/Nandan108/dto-toolkit-laravel)[ Packagist](https://packagist.org/packages/nandan108/dto-toolkit-laravel)[ RSS](/packages/nandan108-dto-toolkit-laravel/feed)WikiDiscussions main Synced 1mo ago

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

DTO Toolkit Laravel Adapter
===========================

[](#dto-toolkit-laravel-adapter)

Laravel adapter for [`nandan108/dto-toolkit`](https://packagist.org/packages/nandan108/dto-toolkit).

This package integrates DTO Toolkit into the Laravel ecosystem. It allows DTOs to:

- be injected directly into controller methods (like `FormRequest`),
- hydrate automatically from the current `Request`,
- throw native Laravel `ValidationException`,
- return JSON responses,
- and read/write Eloquent models via `prop-access`.

The core DTO engine remains framework-agnostic. This package provides Laravel-specific integration only.

---

Requirements
------------

[](#requirements)

- PHP `^8.1`
- Laravel `^10.0 || ^11.0 || ^12.0`
- `nandan108/dto-toolkit` `^1.4.4`

---

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

[](#installation)

```
composer require nandan108/dto-toolkit-laravel
```

The service provider is auto-discovered.

Publish configuration:

```
php artisan vendor:publish --tag=dto-toolkit-config
```

---

Core DTO Base Classes
=====================

[](#core-dto-base-classes)

`FullDto`
---------

[](#fulldto)

`Nandan108\DtoToolkit\Laravel\FullDto`

Extends DTOT’s full DTO behavior and adds:

- `loadRequest()` / `newFromRequest()`
- `exportToJson()`
- `exportToJsonResponse()`

Use this when you want manual request hydration.

---

`RequestDto`
------------

[](#requestdto)

`Nandan108\DtoToolkit\Laravel\RequestDto`

Extends `FullDto`.

When injected into a controller method, it:

- automatically hydrates from the current `Request`,
- runs the DTO processing pipeline,
- throws a native Laravel `ValidationException` if validation fails.

Use this class when replacing `FormRequest`.

---

Controller Example
==================

[](#controller-example)

```
use App\Dto\StorePostDto;
use App\Models\Post;

public function store(StorePostDto $dto)
{
    $post = $dto->exportToEntity(Post::class);
    $post->save();

    return $dto->exportToJsonResponse(status: 201);
}
```

If DTO validation fails:

- Web requests redirect back with session errors.
- JSON requests return HTTP 422 with Laravel’s standard validation error format.

No manual validation code is required.

---

Request Hydration
=================

[](#request-hydration)

DTOs can hydrate from Laravel request “buckets”:

- `route`
- `query`
- `body`
- `json`
- `files`
- `cookies`

The authenticated user is also available via the `user` bucket.

Merge semantics use PHP array union (`+`): **the first included bucket wins for duplicate top-level keys.**

Default bucket order is configurable:

```
// config/dto-toolkit.php
'request_load_include' => ['route', 'query', 'body', 'json', 'files', 'cookies'],
```

Example:

```
final class SearchDto extends FullDto
{
    public ?string $q = null;
    public ?int $page = 1;
}

$dto = SearchDto::newFromRequest($request, ['query']);
```

---

Validation Bridge
=================

[](#validation-bridge)

`Nandan108\DtoToolkit\Laravel\DtoValidationBridge` converts DTOT processing errors into Laravel validation errors:

- Property paths normalized to Laravel dot notation
- Processing trace markers removed
- DTO-level errors mapped to `dto`

`RequestDto` uses this bridge automatically.

As a result, DTOT validators and casters replace traditional Laravel rule arrays, while preserving native Laravel validation behavior.

---

JSON Export Helpers
===================

[](#json-export-helpers)

`FullDto` provides:

- `exportToJson()`
- `exportToJsonResponse()`

Both support:

- optional wrapping key,
- outbound group filtering,
- custom status codes,
- custom headers,
- JSON encoding options.

Example:

```
return $dto->exportToJsonResponse(
    status: 201,
    headers: ['X-Request-Id' => $requestId],
    wrapKey: 'data',
    groups: ['public'],
);
```

These helpers are optional conveniences and do not affect validation behavior.

---

Eloquent PropAccess Adapter
===========================

[](#eloquent-propaccess-adapter)

The package registers Eloquent resolvers for `nandan108/prop-access`:

- `EloquentModelGetterResolver`
- `EloquentModelSetterResolver`

Supported capabilities:

- Dynamic attribute access
- Relation-aware getter and setter handling
- BelongsTo / MorphTo association support
- Accessor/mutator and `Attribute::make` detection
- Cached metadata resolution

> Note: Models are never persisted automatically. Saving remains explicit.

---

Runtime Policies
----------------

[](#runtime-policies)

Configure behavior in `config/dto-toolkit.php`:

```
'write_unknown_attr_policy' => 'allow_unknown',
'relation_access' => 'allow_loaded',
```

### `write_unknown_attr_policy`

[](#write_unknown_attr_policy)

- `allow_unknown` — allow dynamic attributes
- `declared_only` — restrict to declared attributes
- `schema_verified` — validate attribute names against database columns *(recommended for local/testing environments)*

### `relation_access`

[](#relation_access)

- `allow_none`
- `allow_loaded`
- `allow_lazy`

---

Configuration File
==================

[](#configuration-file)

Published at:

```
config/dto-toolkit.php

```

Use this file to configure:

- Request bucket order
- Eloquent policies
- Validation behavior

---

Design Philosophy
=================

[](#design-philosophy)

This adapter:

- preserves DTOT’s framework-agnostic core,
- integrates cleanly with Laravel’s container lifecycle,
- does not replace Laravel’s HTTP layer,
- and does not persist models automatically.

It aims to make DTO Toolkit feel native inside Laravel without sacrificing structure or determinism.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance83

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

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

84d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/024c3beb5cbe22cd3e3f3db6938cf893c09d0b3b90076e2e1566530cd0693372?d=identicon)[Nandan108](/maintainers/Nandan108)

---

Top Contributors

[![Nandan108](https://avatars.githubusercontent.com/u/354944?v=4)](https://github.com/Nandan108 "Nandan108 (2 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nandan108-dto-toolkit-laravel/health.svg)

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

###  Alternatives

[wireui/wireui

TallStack components

1.8k1.3M16](/packages/wireui-wireui)[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4195.3M84](/packages/livewire-volt)[ramonrietdijk/livewire-tables

Dynamic tables for models with Laravel Livewire

21147.4k](/packages/ramonrietdijk-livewire-tables)

PHPackages © 2026

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