Package
Spatie Laravel Data
Create unified resources and data transfer objects
Overview
What Spatie Laravel Data does
Spatie's Laravel Data package allows developers to create unified resources and data transfer objects, simplifying data management across various parts of an application.
Laravel Data provides a way to streamline how data is handled throughout a Laravel application by using rich data objects. These objects replace the need for separate form requests, API transformers, and TypeScript definitions. Essentially, developers can describe their data once and use it consistently across different layers.
The package extends basic PHP objects by introducing a 'Data' class, which offers several key capabilities. These include transforming data objects into resources akin to Laravel's own API resources, and using lazy properties to only fetch what is necessary. Additionally, data objects can be created directly from request data with built-in validation.
A significant advantage is the automatic generation of TypeScript definitions from PHP data objects, facilitating seamless integration with frontend applications. This ensures that data remains typed as it moves between the backend and frontend, reducing potential errors and code duplication.
Developers benefit from writing less validation code, as the PHP type system helps infer validation rules. The ability to save data objects directly as properties of an Eloquent model further integrates them into the Laravel ecosystem, making the package appealing for applications that require consistent data handling practices.
This overview was generated by AI from the package README and may not reflect the latest release.
Read the full README →