Skill: Craft Action
"An Action is a single unit of business logic."
The Standard
- One Public Method:
execute(). - Return Type: Model or void. Never DTO or Response.
- Inject Actions: Use
__constructfor dependencies. - Accept Data: DTOs or primitives in
execute(). - Fluent Chaining: Store input on
$this, chain private methods. Never pass params between them.
The Anti-Patterns
| ❌ Don't | ✅ Do | Why |
|---|---|---|
DB::transaction() in Action |
Transaction in Controller | Prevents composition |
| Validate in Action | Validate in FormRequest | Single responsibility |
Wrap Model::create() only |
Add real logic or skip Action | No value added |
| Return DTO/Response | Return Model or void | Actions aren't HTTP-aware |
| Pass params to private methods | Store on $this, chain methods |
Verbose signatures, no fluency |
Real-World Examples
See examples/.