laravel-controller-cleanup

Refactor Laravel controllers into Form Requests, Actions, and DTOs.

Updated Jun 8, 2025
One-click install
npx skills add https://github.com/noartem/kawa --skill laravel-controller-cleanup-noartem
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel-controller-cleanup
Source: https://github.com/noartem/kawa/tree/main/ui/.ai/skills/laravel-controller-cleanup
Command: npx skills add https://github.com/noartem/kawa --skill laravel-controller-cleanup-noartem

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Keep Laravel controllers lean by moving authentication/validation to Form Requests, extracting business logic to Actions/Services with DTOs, and preferring resource or invokable controllers to keep orchestration clean.

Core Features & Use Cases

  • Move validation to Form Requests and centralize authorization logic.
  • Extract business logic to small Actions or Services with DTOs to decouple from Laravel.
  • Prefer Resource or Single-Action Controllers for standard CRUD or isolated endpoints.
  • Facilitate testing of controllers and Actions/Services with dedicated tests.

Quick Start

Refactor an existing controller by creating a Form Request for validation and a small Action with a DTO, then wire the Action into the controller method.

Frequently Asked Questions about laravel-controller-cleanup

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce Laravel controller bloat and move validation logic out of my routes?

To reduce Laravel controller bloat, move validation and authorization into Form Requests and extract business logic into Actions with DTOs. This shifts orchestration out of controllers and into dedicated, testable classes.

What is the best way to structure Laravel controllers using Actions and DTOs?

The best way to structure Laravel controllers is to prefer resource or invokable controllers for standard CRUD endpoints, wiring small Actions or Services with DTOs into the controller methods to decouple business logic from the framework.

Can I use Form Requests to centralize authorization and validation in Laravel?

Yes, you can use Form Requests to centralize authorization and validation in Laravel. Moving these concerns into Form Requests keeps controllers lean and standardizes validation logic across standard CRUD endpoints.

How do I refactor an existing Laravel controller to use clean architecture?

Refactor an existing Laravel controller by creating a Form Request for validation, extracting the method's logic into a small Action with a DTO, and then wiring that Action into the original controller method.

Does extracting Laravel business logic to Actions and Services improve testability?

Extracting Laravel business logic to Actions and Services with DTOs improves testability by decoupling logic from the framework. This allows you to write dedicated tests for both controllers and the extracted Actions.

When should I use invokable controllers instead of resource controllers in Laravel?

Use invokable controllers in Laravel for isolated single-action endpoints, and use resource controllers for standard CRUD operations. Both approaches help standardize structure and reduce controller bloat.