laravel:controller-cleanup
Controller Cleanup
Keep controllers small and focused on orchestration.
Move auth/validation to Form Requests
- Create a Request class (e.g.,
StoreUserRequest) and useauthorize()+rules() - Type-hint the Request in your controller method; Laravel runs it before the action
php artisan make:request StoreUserRequest
Extract business logic to Actions/Services
- Create a small Action (one thing well) or a Service for larger workflows
- Pass a DTO from the Request to the Action to avoid leaking framework concerns
final class CreateUserAction {
public function __invoke(CreateUserDTO $dto): User { /* ... */ }
}
Prefer Resource or Single-Action Controllers
- Use resource controllers for standard CRUD
- For one-off endpoints, use invokable (single-action) controllers
Testing
- Write feature tests for the controller route
- Unit test Actions/Services independently with DTOs
More from jpcaparas/superpowers-laravel
laravel:routes-best-practices
Keep routes clean and focused on mapping requests to controllers; avoid business logic, validation, or database operations in route files
89laravel:blade-components-and-layouts
Compose UIs with Blade components, slots, and layouts; keep templates pure and testable
89laravel:quality-checks
Unified quality gates for Laravel projects; Pint, static analysis (PHPStan/Psalm), Insights (optional), and JS linters; Sail and non-Sail pairs provided
80laravel:performance-caching
Use framework caches and value/query caching to reduce work; add tags, locks, and explicit invalidation strategies for correctness
77laravel:eloquent-relationships
Define clear relationships and load data efficiently; prevent N+1, use constraints, counts/sums, and pivot syncing safely
76laravel:tdd-with-pest
Apply RED-GREEN-REFACTOR with Pest or PHPUnit; use factories, feature tests for HTTP, and parallel test runners; verify failures before implementation
76