laravel-best-practices

Audit Laravel codebases against best practices for Eloquent, routing, and architecture.

3|1|Updated Jun 26, 2025
One-click install
npx skills add https://github.com/jasonencode/saas --skill laravel-best-practices-jasonencode
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel-best-practices
Source: https://github.com/jasonencode/saas/tree/main/.trae/skills/laravel-best-practices
Command: npx skills add https://github.com/jasonencode/saas --skill laravel-best-practices-jasonencode

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Laravel projects often drift into inconsistent patterns across controllers, models, migrations, and services, leading to hard maintenance, security risks, and performance issues. This Skill provides a consolidated set of Laravel best practices to standardize code, improve readability, and accelerate safe refactoring.

Core Features & Use Cases

  • Consistent patterns for Eloquent models, relationships, and queries to prevent N+1 problems.
  • Architectural guidance (actions, service classes, contracts) to improve testability and decoupling.
  • Validation, routing, testing, and security guidelines to reduce bugs and vulnerabilities.
  • Real-world use: refactor a legacy controller to use local scopes, proper policies, and single-responsibility actions.

Quick Start

Audit your Laravel codebase against the official guidance to identify inconsistencies and opportunities for improvement.

Frequently Asked Questions about laravel-best-practices

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

FAQPage Schema
How do I fix N+1 query problems in Laravel Eloquent?

Fix Laravel N+1 query problems by applying consistent Eloquent patterns and using local scopes to optimize model relationships. This ensures queries load efficiently and prevents performance bottlenecks in your application.

What is the best way to refactor a legacy Laravel controller?

The best way to refactor a legacy Laravel controller is extracting logic into single-responsibility action classes and service classes. This architectural guidance improves testability, reduces bloated controllers, and enforces proper decoupling.

How do I enforce Laravel security and validation best practices?

Enforce Laravel security and validation best practices by applying documented rules for routing, policies, and data validation. This reduces vulnerabilities and bugs by ensuring consistent authorization checks across your application.

Does this Laravel best practices guidance work for legacy projects?

Yes, this guidance works for legacy Laravel projects by auditing existing controllers, models, and migrations. It identifies architectural inconsistencies and accelerates safe refactoring to improve maintainability without rewriting the entire codebase.

When should I use service classes and contracts in Laravel architecture?

Use service classes and contracts in Laravel architecture when you need to decouple business logic from controllers and improve testability. This approach standardizes code, improves readability, and prevents logic duplication across your application.

How do I structure Laravel testing for better code maintainability?

Structure Laravel testing by following established guidelines for validation, routing, and architectural decoupling. This improves testability by isolating business logic into actions and service classes, ensuring your tests remain robust and maintainable.