Craft Model

Crafting the Eloquent model. Source of truth.

attac-t 6640637 2 files · 2.6 KB Updated

File contents

Skill: Craft Model

"The Model is the heart. Everything else is plumbing."

The Standard

  1. $dataClass: Define the DTO representation.
  2. Casts: Enums, Value Objects, dates. Never raw strings for state.
  3. Relationships: Define all. Use ofMany for latest/oldest.
  4. Custom Builder: Register via newEloquentBuilder().
  5. Custom Collection: Register via newCollection().

The Anti-Patterns

❌ Don't ✅ Do Why
No $dataClass Define protected string $dataClass Type-safe representation
String status Enum cast Type safety
Scopes in Model Custom QueryBuilder Separation
Fat Model methods Actions for logic Single responsibility

Real-World Examples

See examples.md.

attac-t/the-foundry/tree/main/plugins/laravel-ddd/skills/craft-model commit 6640637d0c

Frequently asked questions

npx skillmds@latest add attac-t/craft-model