refactor:laravel

Refactor PHP and Laravel code using PHP 8.3+ features and Laravel 11+ patterns.

Updated Feb 20, 2026
One-click install
npx skills add https://github.com/garethdaine/agent --skill refactor-laravel-garethdaine
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor:laravel
Source: https://github.com/garethdaine/agent/tree/main/.cursor/skills/refactor-laravel
Command: npx skills add https://github.com/garethdaine/agent --skill refactor-laravel-garethdaine

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses the challenges of maintaining and scaling PHP/Laravel applications by refactoring code to improve its structure, readability, and adherence to modern best practices, thereby reducing technical debt and enhancing developer productivity.

Core Features & Use Cases

  • Modern PHP Adoption: Integrates PHP 8.3+/8.4+ features like property hooks, typed constants, and #[\Override] attributes.
  • Laravel Best Practices: Enforces Laravel 11+ patterns such as simplified structure, Actions, and thin controllers.
  • SOLID Principles: Applies DRY, SRP, and other object-oriented design principles.
  • Anti-Pattern Correction: Identifies and rectifies common issues like fat controllers, N+1 queries, and magic strings.
  • Use Case: Refactor a legacy Laravel controller with complex business logic into a set of lean controllers and dedicated service classes, improving maintainability and testability.

Quick Start

Use the refactor:laravel skill to refactor the provided controller code to adhere to Laravel 11+ best practices.

Frequently Asked Questions about refactor:laravel

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

FAQPage Schema
How do I refactor a fat controller in Laravel to improve maintainability?

To refactor a fat Laravel controller, move business logic into dedicated service classes and implement thin controllers. This approach enforces the Single Responsibility Principle, reduces code duplication, and significantly improves the testability of your application.

What's the best way to fix N+1 query problems in Laravel applications?

Fixing N+1 query problems in Laravel involves refactoring database access patterns to use eager loading. By applying SOLID principles and modern Laravel 11+ patterns during refactoring, you eliminate inefficient loops and optimize data retrieval for better performance.

How do I upgrade legacy PHP code to use modern PHP 8.3 and 8.4 features?

Upgrading legacy PHP code involves refactoring existing structures to adopt PHP 8.3+ features like property hooks, typed constants, and the #[\Override] attribute. This modernization process enhances type safety, reduces boilerplate, and aligns the codebase with current standards.

Does refactoring Laravel code require strict adherence to SOLID principles?

Refactoring Laravel code to enforce SOLID principles is highly recommended for reducing technical debt. Applying DRY and Single Responsibility patterns ensures that your refactored controllers and services remain modular, readable, and easier to scale as the application grows.

When should I move business logic out of my Laravel controllers?

You should move business logic out of Laravel controllers when the controllers become bloated and difficult to maintain. Refactoring into Action classes and dedicated services transforms complex, legacy PHP patterns into a simplified Laravel 11+ structure.