Craft Query

Crafting QueryBuilders. Eloquent power, not Repositories.

attac-t c77c373 2 files · 2.5 KB Updated

File contents

Skill: Craft Query

"Eloquent is a superpower. Don't hide it behind a Repository."

The Standard

  1. No Repositories: Use Custom QueryBuilders.
  2. Atomic Methods: Composable (->pending()->forUser($u)).
  3. Return Self: Always return $this for chaining.
  4. Descriptive Names: pending(), not wherePending().

The Anti-Patterns

❌ Don't ✅ Do Why
Repository pattern QueryBuilder Eloquent is already the abstraction
One-off scope methods Reusable builder methods DRY
whereStatus('pending') pending() Semantic clarity
Update logic in builder Actions for mutations Builders query, Actions mutate

Real-World Examples

See examples.md.

attac-t/the-foundry/tree/main/plugins/laravel-ddd/skills/craft-query commit c77c373b4b

Frequently asked questions

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