zero-to-prod/data-model
Type-safe PHP data models that hydrate from arrays/JSON via a single from($data) call. Uses reflection, type hints, and #[Describe] attributes for defaults, required/nullable rules, casting, and assignment—ideal for APIs, DB rows, and user input.
Describe attributes, centralizing rules.pre/post hooks) directly in data models, reducing service-layer complexity.fill() calls or Arrayable/Jsonable traits with type-safe hydration (e.g., converting API responses to Eloquent models or custom DTOs).#[Describe(['required' => true])] on event properties).Config::from($_ENV)).User::from(['name' => 'Test']) vs. manual object assembly).Adopt if:
isset() checks, manual casting).Look elsewhere if:
"This package lets us write less code while reducing bugs in how we handle data. Instead of manually wiring API responses or database rows into objects—with all the isset() checks, type casts, and validation rules scattered across constructors—we declare the rules once, in a single attribute. This cuts development time by 30–50% for DTOs and makes our data layer self-documenting and verifiable. For example, a User DTO that previously required 15 lines of constructor logic can be defined in 3 lines with #[Describe]. It also future-proofs our API contracts by embedding validation rules directly in the type system."
ROI:
*"Problem: Our DTOs are a mess of manual hydration, duplicated validation, and magic strings. Every time we add a new field or change a type, we risk breaking consumers.
Solution: zero-to-prod/data-model gives us declarative, type-safe hydration with:
User::fromArray($data) with User::from($data).required, cast, and default values next to the property (no more scattered logic).User::from(['address' => [...]])).pre/post hooks to enforce rules (e.g., reject negative ages).Migration Path:
fill() calls with from().pre for domain rules).DataModelHelper for collections (e.g., User::fromArray($users)).Trade-offs:
#[Describe] attributes (but pays off quickly).Next Steps:
DataModel and measure dev time saved.zero-to-prod/data-model-helper for collections, transformable for output formatting.Key Selling Point for Engineers: "This is like Laravel’s Eloquent models, but for DTOs. You get all the magic (hydration, validation, casting) without the ORM overhead."
How can I help you explore Laravel packages today?