spatie/laravel-data
Spatie Laravel Data lets you define rich data objects once and reuse them as form requests, API transformers, and TypeScript definitions. It supports automatic validation, resource transformation, lazy properties, and constructing objects from request data.
Architecture fit
spatie/laravel-data is a Laravel-native layer, not a framework-agnostic library. Its value proposition is collapsing three artifacts into one class: form request validation, API transformer/resource, and frontend type definition. That is a genuine architectural consolidation, not a convenience wrapper — it targets a real duplication cost in any Laravel app with a typed frontend.extends Data) in the domain layer. It is weakest in codebases with an established, hand-rolled DTO or resource convention, or where the domain model must stay framework-free.Integration feasibility
Technical risk
toArray() on null, Inertia deferred prop flexibility, lazy class recognition, CannotCreateData on unloaded relationships). Frequent patching is a health signal; frequent regression patching is a stability signal. Pin exactly and upgrade deliberately.Key questions
Stack fit
Migration path
rules() overrides where inference is insufficient. This is where the "write validation once" payoff actually lands.Compatibility
composer update.Sequencing
Maintenance
Support
Scaling
Failure modes
CannotCastEnum, CannotCreateData on unloaded relationships) surfacing as 500s rather than handled validation responses. Mitigate with exception handling at the boundary and explicit tests for unloaded-relationship paths.Ramp-up
rules()) is where the learning curve and the subtle bugs live.rules(), when not to reach for lazy properties, how to handle nested collections); pair review on the first several DTOs.Recommendation: Approve as a scoped pilot (Phases 1–2) on new and low-risk endpoints, with pinned versions, a deploy-time cache-clear hook, and contract tests as entry criteria. Gate broader rollout on measured developer-time savings and zero serialization regressions. Do not mandate a fleet-wide retrofit.
How can I help you explore Laravel packages today?