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 attribute, reducing boilerplate in services/repositories.Illuminate\Support\Collection and Illuminate\Database\Eloquent\Model (e.g., for API responses or form requests).spatie/array-to-object but with stricter typing and fewer edge cases.User::from($request->all())).from() is preferred).Describe to integrate with Laravel’s event system (e.g., pre/post hooks triggering ModelEvents).via or custom from() methods).Describe for all DTOs.pre/post hooks or nested via calls can obfuscate data flow. Enforce simplicity via code reviews.Describe configurations (e.g., required fields, casts).ReflectionAttribute instances for hot paths (e.g., API responses)?php artisan make:model to auto-generate Describe attributes?Describe IDE plugin for VSCode/PhpStorm?PropertyRequiredException to API consumers (e.g., as HTTP 422 with validation-like errors)?Validator to reuse Describe rules?StoreUserRequest::from($request->all())).via methods or base model traits).Describe rules can map to Laravel’s Validator (e.g., required → required|string).DataModel for stricter typing.DataModel to define serialization rules declaratively.new User($request->input()) with User::from($request->all()).DataModel trait to new DTOs; keep existing constructors for backward compatibility.from() instead of manual hydration.@deprecated PHPDoc).php artisan make:datamodel stub to auto-generate Describe attributes.DataModel IDE plugin to highlight missing/incorrect attributes.#[Describe(['ignore'])] to exclude properties from from() hydration.Illuminate\Foundation\Http\FormRequest to use DataModel::from() for validation.toArray() with Describe-driven serialization (via Transformable package).DataModel interfaces to concrete implementations.via to hydrate Eloquent models from query results (e.g., User::from($user->toArray())).zero-to-prod/data-model to composer.json.post-install-cmd (as shown in README).Describe attributes via workshops.DataModel style guide (e.g., "Always use required for non-nullable fields").UserResource::toArray() with a UserResource class using DataModel for serialization.from() hydration in key workflows (e.g., user registration).Describe configurations (e.g., "cast to uppercase").from() execution time).PropertyRequiredException rates to validate data quality.Describe attributes replace 5–10 lines of constructor logic per property.Describe can make classes verbose. Mitigate with:
Describe configurations (e.g., base traits for common casts).Describe keys.PropertyRequiredException need clear documentation on how to:
PropertyRequiredException to JSON:API errors).catch (PropertyRequiredException $e) {
return response()->json([
'errors' => [['field' => $e->getProperty(), 'message' => $e->getMessage()]]
], 422);
}
ReflectionAttribute instances for static properties.Describe attributes (e.g., only parse when from() is called).Describe configurations (e.g., serialize to JSON at boot).via to batch-hydrate collections (e.g., User::fromMany($array)).via to hydrate models from query results without N+1 queries:
class User extends Model {
use DataModel;
#[Describe(['via' => [
How can I help you explore Laravel packages today?