Powerful data objects for Laravel
Laravel Data enables you to create rich, type-safe data objects that work seamlessly throughout your entire application. Using this package, you only need to describe your data structure once.Form Requests
Replace form request classes with data objects that handle validation automatically
API Resources
Transform data objects into JSON responses without writing separate transformer classes
TypeScript Definitions
Generate TypeScript definitions from your data objects for end-to-end type safety
What is a data object?
A Laravel Data object is a regular PHP class that extends fromData. This simple inheritance unlocks powerful functionality:
Key features
By extending fromData, you enable powerful capabilities:
Automatic Transformation
Convert data objects into arrays, JSON, or resources like Laravel API resources
Lazy Properties
Transform only requested parts of data objects with lazy loading support
Request Validation
Create data objects from request data with automatic validation
Flexible Creation
Construct data objects from arrays, models, requests, or any custom type
Eloquent Integration
Save data objects as properties of Eloquent models
TypeScript Generation
Export TypeScript definitions for frontend type safety
Why use Laravel Data?
Type safety across your stack
Type safety across your stack
Ensure data is properly typed when it leaves your app and comes back from the frontend, reducing errors significantly.
Write less, do more
Write less, do more
Stop writing the same properties three times (in a resource, DTO, and request validation). Define them once.
Less validation boilerplate
Less validation boilerplate
Many validation rules are obvious through PHP’s type system, so you write fewer explicit rules.
Free TypeScript definitions
Free TypeScript definitions
Get TypeScript versions of your data objects automatically generated for your frontend.
Quick example
Here’s how Laravel Data simplifies your controllers. Instead of this:Next steps
Requirements
Check if your environment meets the requirements
Installation
Install Laravel Data via Composer
Quickstart
Build your first data object in minutes
GitHub
View source code and contribute