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

Data Model Laravel Package

zero-to-prod/data-model

DataModel hydrates PHP objects from external data with a single from($data) call using reflection and type hints. Validation and casting live in #[Describe] attributes (required, nullable, default, assign), replacing manual property wiring and scattered null checks.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Where transformation logic lives. The package makes "hydrate a typed object from an array" a single declarative line (#[Describe([...])]) instead of scattered constructor assignments, service-layer casting, and defensive isset() guards. That's a real architectural decision: DTO-centric mapping versus logic smeared across controllers, form requests, and Eloquent accessors.
  • Build vs. buy for the mapping layer. Every Laravel product eventually grows an in-house "array → object" helper. This package is a candidate off-the-shelf answer, and the assessment forces the honest comparison against the de facto Laravel incumbent (spatie/laravel-data) and against just using Eloquent casts plus validated arrays.
  • API integration roadmap. The strongest use case is inbound external data: third-party API responses, webhook payloads, partner feeds, legacy DB reads. If the roadmap includes several integrations, a consistent hydration convention pays compounding dividends in review speed and defect rate.
  • Domain boundary decisions. Using DTOs at the edge of the domain (instead of passing Eloquent models or raw arrays inward) is a testability and coupling decision. The README explicitly supports hydrating from a Laravel model, arrays, collections, and nested objects, which makes "introduce a DTO seam here" a cheap, incremental call rather than a refactor.
  • Convention standardization. The attribute is the contract — required, nullable, default, cast, from, assign all live next to the property. That is a code-review and onboarding decision as much as a technical one, and it is unusually friendly to static analysis and to AI-assisted code generation (the README markets this explicitly as "low token cost").
  • Risk posture on dependencies. With 139 stars and zero dependents, adopting this is a deliberate bet on a young, single-maintainer, MIT package. That is itself a product decision about acceptable dependency risk for non-critical infrastructure.
  • Migration sequencing. Because it's a trait (no base class, no interface), adoption can be incremental — one DTO, one integration, one sprint. That supports a "pilot then expand" roadmap rather than a big-bang migration.

When to Consider This Package

Consider it when:

  • You are on modern PHP (8.x, ideally 8.2+) and want typed DTOs without pulling in a large framework.
  • You have repetitive, nested, externally-shaped payloads — webhooks, partner APIs, config blobs — where recursive hydration into nested classes is the bulk of the work.
  • You want per-property resolution rules that are inspectable in one place: remap a key, cast a value, run a validation hook, set a default, mark required.
  • Your team values static-analysis surfaces and readability over batteries-included features.
  • You need an escape hatch for custom metadata (the $extra capture) — e.g., attaching UI labels or validation hints without subclassing.
  • The integration is non-critical or well-isolated, so package risk is containable.

Look elsewhere when:

  • You are a Laravel shop already standardized on spatie/laravel-data. It has far broader adoption, first-party Laravel validation integration, resource/transformation support, and a much larger community to hire from. Switching costs likely exceed any ergonomic gain here.
  • You need integrated validation, authorization, OpenAPI/schema generation, or serialization round-tripping as first-class features — this package deliberately stops at hydration plus hooks.
  • You need vendor support, multiple maintainers, or a track record of downstream production usage. Zero dependents is the single loudest signal in this evaluation; there is no public evidence of who else runs it in production.
  • Performance is a hot-path concern. Reflection-driven hydration on every request deserves a benchmark before it lands in a high-throughput path.
  • Your org requires dependency vetting with CVE history, long-term support commitments, or an LTS policy.

How to Pitch It (Stakeholders)

To executives (one paragraph): We have a recurring cost every time we integrate with an external system: hand-written mapping code that drifts, breaks silently, and is tedious to review. This is a small MIT-licensed PHP package that replaces that boilerplate with a declarative attribute on each property. It's low-cost to trial, requires no architectural change (it's a trait, adopted one class at a time), and its rules are visible to static analysis. The trade-off is maturity: it is a young, single-maintainer package with limited public adoption, so I recommend a scoped pilot on one non-critical integration rather than a standard-mandate, with the mapping isolated behind our own interface so we can swap it out at low cost.

To engineering (the substance):

  • Trait-based, no base class, no interface — drop use DataModel; on a class, call Class::from($data). Works with arrays, objects, or nothing.
  • Reflection-driven property resolution with a documented, first-match-wins precedence order (assign → default → cast → post → method-level cast → class-level cast → via → native assignment). That precedence table is the thing to review hardest — it is the package's real API.
  • Recursive hydration of class-typed properties removes the most annoying boilerplate in nested payloads.
  • Lifecycle hooks (pre/post) let us centralize invariant checks next to the property rather than in a service; explicit exceptions (PropertyRequiredException, InvalidValue, DuplicateDescribeAttributeException) mean failures are typed and catchable rather than null propagating.
  • Composable per-property keys (from + cast + default) beat control-flow-heavy custom hydrators for reviewability.
  • Companion packages exist (helper mapOf, factory, transformable), which covers the collection-transform cases we would otherwise hand-roll.

The honest counter-pitch to put on the same slide:

  • 139 stars, 0 dependents, opportunity score 18 — this is unproven in the wild. Treat it as a bet, not a standard.
  • Single-maintainer risk with an active release cadence; pin the version and read the changelog on upgrade.
  • Laravel's own ecosystem already has a strong answer (spatie/laravel-data); we should benchmark our first two DTOs against it before committing either way.

The ask: one sprint, two or three real DTOs on a non-critical integration, wrapped behind our own mapping interface. Success criteria: measurable reduction in mapping LOC and review time, no reflection-related latency regression, and a clear answer on whether to standardize, keep it local, or revert to spatie/laravel-data.

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.
wandesnet/mercadopago-laravel
tsfcorp/email
larafony/core
laravel-enso/currencies
tartan/laravel-online-payment
gam/laravel-sat-catalogs
cloudcreativity/laravel-stripe
abdulelahragih/querybuilder
wedevbr/celcoin-laravel
surazdott/nepali-date
devsquad-cockpit/laravel
coding-socks/laravel-upload-handler
artisanbarista/laravel-shield
shopwwi/laravel-cache
instance-code/repository
flooris/prestashop-models
lab2view/laravel-generator
lenderspender/laravel-wizard
joecampo/laravel-notification-basecamp
square1/laravel-collection-rolling-average