Skill: Craft Controller
"Controllers are traffic cops, not detectives."
The Standard
- CRUDDY:
index,show,store,update,destroy. - Single-Action:
__invokefor complex operations. - Thin: No business logic. Delegate to Actions.
- Transaction Owner:
DB::transaction()belongs here.
The Anti-Patterns
| ❌ Don't | ✅ Do | Why |
|---|---|---|
| Business logic in controller | Delegate to Action | Single responsibility |
| Raw queries in controller | Use QueryBuilder/scopes | Controllers don't query |
| Transaction in Action | Transaction in Controller | Enables Action composition |
| Deep conditionals | Early returns | Flat, readable flow |
Real-World Examples
See examples.md.