Laravel Architecture

Enforce Laravel architectural standards using Service classes and Form Requests.

51|6|Updated Mar 28, 2019
One-click install
npx skills add https://github.com/Mte90/dotfiles --skill laravel-architecture-mte90
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Laravel Architecture
Source: https://github.com/Mte90/dotfiles/tree/main/.config/opencode/skills/laravel/architecture
Command: npx skills add https://github.com/Mte90/dotfiles --skill laravel-architecture-mte90

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill enforces best practices for building scalable and maintainable Laravel applications, preventing common architectural pitfalls.

Core Features & Use Cases

  • Enforces SOLID principles: Promotes Single Responsibility Principle (SRP) through clear separation of concerns.
  • Promotes Dependency Injection: Encourages the use of Laravel's Service Container for managing dependencies.
  • Use Case: Ensure new features in a large Laravel project adhere to established architectural patterns, making the codebase easier to understand, test, and extend.

Quick Start

Apply the Laravel Architecture skill to refactor the provided controller code to follow the skinny controller pattern.

Frequently Asked Questions about Laravel Architecture

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

FAQPage Schema
How do I refactor a fat Laravel controller to follow the skinny controller pattern?

To refactor a fat Laravel controller into a skinny controller, extract business logic into dedicated Service or Action classes. This enforces the Single Responsibility Principle, keeping controllers focused on HTTP request handling and routing data to the service layer.

Why should I use dependency injection instead of manual instantiation in Laravel?

Using dependency injection instead of manual instantiation in Laravel leverages the Service Container to manage class dependencies. This approach improves code testability, decouples components, and ensures scalable architecture by resolving dependencies automatically.

What is the best way to handle inline validation in Laravel for better architecture?

The best way to handle inline validation in Laravel is to replace it with Form Requests. This separates validation logic from controllers, adhering to Separation of Concerns and making the codebase easier to maintain, test, and extend.

When do I need a service layer in my PHP application?

You need a service layer in your PHP application when controllers become bloated with business logic. Implementing a service layer enforces contract-first design, separates concerns, and ensures new features adhere to established architectural patterns for scalability.

Does Laravel architecture enforce SOLID principles for large projects?

Laravel architecture can enforce SOLID principles for large projects by promoting the Single Responsibility Principle through clear separation of concerns. Using Service classes and Dependency Injection ensures the codebase remains easier to understand, test, and extend.