Projectsphp-dataInstallation

PHP Data

Package

Lightweight, framework-agnostic Data Transfer Object (DTO) library with first-class Laravel integration.

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:

PackageEnables
laravel/framework (or illuminate/*)Eloquent model hydration, Illuminate\Support\Collection results from collect(), paginator wrapping, config() integration
nesbot/carbonAutomatic 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