Installation
Requirements
- PHP 8.3+
- Laravel 13+ (optional — only for the Laravel-specific conveniences)
The core DTO features (from(), make(), toArray(), attributes, nested data)
run with no Laravel installed. See Framework-agnostic usage.
Install
composer require bradietilley/laravel-data
There is no service provider to register and no config to publish — the package works as soon as it is autoloaded.
Optional dependencies
These unlock extra behaviour when present; the library detects them at runtime and degrades gracefully when they are absent:
| Package | Enables |
|---|---|
laravel/framework (or illuminate/*) | Eloquent model hydration, Illuminate\Support\Collection results from collect(), paginator wrapping, config() integration |
nesbot/carbon | Automatic Carbon / CarbonImmutable casting in from() and formatting in toArray() |
Verifying the install
use BradieTilley\Data\Data;
$data = (new class('hi') extends Data {
public function __construct(public string $message) {}
})->toArray();
// ['message' => 'hi']
Next steps
- Data Objects — define your first DTO
- Hydration — build instances from arrays, models, and more