Skill: Craft Concern
"A concern wires behavior. It never owns it."
The Standard
- Thin Methods: Delegate to query builders, collections, and actions.
- Naming:
Has*,Interacts*,Can*— match Laravel conventions. - No Business Logic: Conditionals or transformations? Extract.
- Boot Convention: Use
boot{TraitName}for model event hooks.
A concern method does one of three things:
| Delegation Target | Concern Method Does |
|---|---|
| QueryBuilder | Returns a query scope or builder |
| Collection | Returns a filtered/mapped collection |
| Action | Calls an action and returns result |
If it does more, it's too fat. Extract.
The Anti-Patterns
| Don't | Do | Why |
|---|---|---|
| Business logic in trait | Delegate to Action | Traits mix in, logic leaks |
| Complex queries inline | Delegate to QueryBuilder | Reusable, testable |
| Collection manipulation | Delegate to custom Collection | Named pipeline |
| Deep conditionals | Guard clause or Action | Traits should be flat |
| State mutations | Delegate to Action | Side effects belong in Actions |
Real-World Examples
See examples.md.