Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Data Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

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.
  • Fit is strongest where the application already has (a) a JSON API boundary, (b) a TypeScript/Inertia/Livewire consumer, and (c) a codebase disciplined enough to accept a shared base class (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.
  • The package is reflection-driven and generates internal metadata about each data class. That is the core architectural trade-off: rich declarative behavior in exchange for a reflection cost, a metadata cache to manage, and implicit behavior that is only visible via attributes.

Integration feasibility

  • Installation is a single Composer require with no database migration required for the base feature set. Optional capabilities (storing data objects as Eloquent model properties) do require a JSON column and a cast — a schema decision, not a package constraint.
  • Adoption is naturally incremental: one endpoint, one DTO, one validation surface at a time. There is no mandatory global registration or bootstrapping that forces a big-bang cutover.
  • Compatibility posture is current: the changelog shows Laravel 12 support in 4.13.1, and Laravel 13 / Livewire 4 support plus a PHP 8.1 drop in 4.20.0. This means the package tracks upstream Laravel aggressively, but also that PHP/Laravel version selection constrains which minor you can run.

Technical risk

  • Release churn (elevated). The 4.14–4.21 window shows a high cadence of minors and patches, several of which fix regressions introduced shortly before (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.
  • Cache-as-deployment-dependency. 4.14.0 explicitly instructs users to clear cached data-object metadata on deploy because internal structures changed. A stale cache is a silent, hard-to-diagnose failure mode that lands in production, not in code review.
  • Minor-version behavior changes. 4.17.0 shipped validation-attribute internals changes described as "technically not breaking." Semantic-versioning-adjacent risk for a validation layer is material — validation drift is a security- and data-integrity-adjacent failure.
  • Serialization contract drift. Swapping existing API resources for data objects can change output shape (key casing, null handling, nested collections, lazy exclusion). This is the highest-impact risk for external consumers and needs contract tests, not eyeballing.
  • Bus-factor and support model. MIT-licensed, Spatie-backed, but effectively a single primary maintainer with community PRs. No commercial SLA. Acceptable for a library of this type; not acceptable as a critical-path dependency without the ability to fork or pin.
  • Metadata reliability caveat. "Dependents: 0" is almost certainly a graph-scrape artifact rather than reality (Packagist download volume for Spatie packages of this class is orders of magnitude larger). Do not use it as an adoption signal in either direction — verify against Packagist stats and a GitHub code search before relying on it.
  • Score interpretation. Overall 51.58 with opportunity 63.67 and 1,802 stars reads as "credible, well-documented, under-hyped tooling with real utility but non-trivial operational overhead." That is consistent with a deliberate, bounded pilot rather than a fleet-wide mandate.

Key questions

  1. What are our exact PHP and Laravel version floors, and does that pin us below 4.20.0?
  2. Which boundary are we standardizing — inbound requests, outbound resources, or both? Scope creep here is the main cost driver.
  3. Is our API output contract versioned and contract-tested today? If not, the risk of swapping resources for data objects is unquantified.
  4. Do we have a deploy hook that clears the package's metadata cache, and does it run reliably on every environment including rollbacks?
  5. What is the p95 payload size and nesting depth on our heaviest endpoint? Reflection and transformation cost scales with graph complexity.
  6. Is TypeScript generation a real requirement (then this package is high-leverage) or aspirational (then it is a feature we will pay maintenance for and not use)?
  7. Who owns the upgrade treadmill — reviewing changelogs and running the test suite on each minor?

Integration Approach

Stack fit

  • Strong fit: Laravel 11/12/13, PHP 8.2+, JSON API, TypeScript/Inertia/Livewire frontend, Eloquent-backed persistence.
  • Weak fit: multi-framework monorepo, PHP < 8.2, non-Laravel services, or a domain layer with a hard "no framework imports" rule.
  • Native synergies worth exploiting: replacing form requests on write paths, replacing API resources on read paths, generating TS definitions in CI, and Eloquent casts for JSON-shaped value objects.

Migration path

  • Phase 1 — Read-only proof. Introduce data objects on two or three low-risk GET endpoints behind existing resources, compare outputs byte-for-byte in tests. Zero user-visible change.
  • Phase 2 — Inbound validation. Move form-request-heavy write endpoints to data objects with inferred rules plus explicit rules() overrides where inference is insufficient. This is where the "write validation once" payoff actually lands.
  • Phase 3 — Contract hardening. Snapshot tests on serialized output; publish generated TypeScript types to the frontend build. Only now retire legacy resources.
  • Phase 4 — Optional advanced surfaces (Eloquent casts for value objects, Inertia deferred props, lazy properties) once the team is fluent. Do not lead with these.

Compatibility

  • Lock to a specific minor, not a caret range, during the pilot. Upgrade on a schedule with changelog review, not on composer update.
  • Confirm behavior of any existing custom casts, accessors, and API resource conditionals before assuming 1:1 parity.
  • Verify Inertia and Livewire versions against the supported matrix before enabling those integrations.

Sequencing

  • Dependency and cache-clear deploy hook first (cheap, and it prevents the most common production failure).
  • Then DTO layer on new code only — do not retroactively convert existing endpoints during the pilot.
  • Then CI jobs for snapshot/contract tests and TS generation.
  • Then, and only then, consider backfilling legacy endpoints. Backfill is the largest and least valuable tranche; keep it explicitly out of the initial scope.

Operational Impact

Maintenance

  • Ongoing cost is real and recurring: changelog review, minor-version upgrade testing, and occasional refactors when internals shift (4.14.0 is the precedent).
  • Budget roughly a few days per quarter for the upgrade treadmill plus the pilot integration effort (order of one to two weeks for a couple of endpoints including contract tests). Underestimating this is the most common failure of this kind of adoption.
  • Pin and document the version in the repo; treat upgrades as reviewed changes with a rollback plan.

Support

  • Community support only: GitHub issues, Spatie's documentation site (v4), changelog as the authoritative record. No vendor SLA, no paid support tier for this package specifically.
  • Mitigation: the MIT license and readable internals mean an internal fork or patch is feasible. For a library at the validation/serialization boundary, that optionality is the real safety net and should be stated explicitly in the risk register.

Scaling

  • Metadata caching is mandatory in production. Without it, reflection runs per request and cost grows with the number and complexity of data classes touched per request.
  • Payload-shaped cost: deep nested collections and eager-loaded relationship graphs convert into proportional transformation work. Establish a p95 latency baseline on the heaviest endpoint before and after.
  • Horizontal scaling is unaffected — this is stateless application-layer work. The only shared state is the metadata cache, which must be consistent across instances after each deploy.

Failure modes

  • Stale metadata cache post-deploy → type errors or wrong serialization, often on a subset of instances. Highest likelihood, highest confusion. Mitigate with a mandatory cache-clear in the deploy pipeline and on rollback.
  • Validation gaps → inferred rules diverge from intended constraints; an endpoint that "looked validated" accepts bad input. Mitigate with explicit rules plus negative tests on every migrated endpoint.
  • Serialization drift → silent contract change for API consumers or frontend. Mitigate with snapshot/contract tests asserting the exact JSON shape.
  • Cast and construction exceptions (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.
  • Minor-version behavior change in validation internals invalidating an assumption nobody re-tested. Mitigate with pinned versions and full-suite runs on upgrade.

Ramp-up

  • Moderate. The base class is trivial; the attribute-driven surface (input name mapping, casts, lazy/conditional properties, validation attributes, rules()) is where the learning curve and the subtle bugs live.
  • Practical enablement: one engineer goes deep on the docs and owns the pattern; a short internal writeup of the sanctioned patterns and anti-patterns (when to use explicit rules(), when not to reach for lazy properties, how to handle nested collections); pair review on the first several DTOs.
  • Frontend benefit (free TypeScript types) is the fastest way to build team buy-in, but only if generation is wired into CI and actually consumed — otherwise it is a demo, not a capability.

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.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
abbasudo/artisan-route
mirvan/ippanel
ignibyte/aic-framework
glavweb/data-schema-bundle
glavweb/datagrid-bundle
tacticmedia/scim-server
uni-method/frame
neika-ai/sdk
adachsoft/php-code-style
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
adachsoft/api-version-bundle
cgv/localized-resource
noith/settings
kda/laravel-package