laravel-best-practices
Laravel 13 conventions and best practices. Use when creating controllers, models, migrations, validation, services, or structuring Laravel applications. Triggers on tasks involving Laravel architecture, Eloquent, database, API development, or PHP patterns.
By asyrafhussin · 1,897 installs
npx skills add asyrafhussin/agent-skills --skill laravel-best-practices
Source repository · Upstream listing
Laravel 13 Best Practices
Comprehensive best practices guide for Laravel 13 applications. Contains 31 rules across 7 categories for building scalable, maintainable Laravel applications.
When to Apply
Reference these guidelines when:
Creating controllers, models, and services
Writing migrations and database queries
Implementing validation and form requests
Building APIs with Laravel
Structuring Laravel applications
Rule Categories by Priority
Priority Category Impact Prefix
1 Architecture & Structure CRITICAL arch
2 Eloquent & Database CRITICAL eloquent
3 Controllers & Routing HIGH controller , ctrl
4 Validation & Requests HIGH validation , valid
5 Security HIGH sec
6 Performance MEDIUM perf
7 API Design MEDIUM api
Quick Reference
1. Architecture & Structure (CRITICAL)
arch service classes Extract business logic to services
arch action classes Single purpose action classes
arch repository pattern When to use repositories
arch dto pattern Data transfer objects
arch value objects Encapsulate domain concepts
arch event driven Decouple with events and listeners
arch feature folders Organize by domain/feature
arch queue routing Centralized job queue routing (Laravel 13+)
2. Eloquent & Database (CRITICAL)
eloquent eager loading Prevent N+1 queries
eloquent chunking Process large datasets
eloquent query scopes Reusable query logic
eloquent model events Use observers for side effects
eloquent relationships Define relationships properly
eloquent casts Automatic attribute casting
eloquent accessors mutators Transform attributes
eloquent soft deletes Safe deletion with recovery
eloquent pruning Automatic cleanup of old records
eloquent vector search Semantic search with pgvector (Laravel 13+)
3. Controllers & Routing (HIGH)
controller resource controllers Use resource controllers
controller single action Single action invokable controllers
controller resource methods RESTful resource methods
controller form requests Use form requests
controller api resources Transform API responses
controller middleware Apply middleware properly
controller dependency injection Inject dependencies
4. Validation & Requests (HIGH)
validation form requests Use form request classes
validation custom rules Create custom rules
validation conditional rules Conditional validation
validation array validation Validate nested arrays
validation after hooks Complex validation logic
5. Security (HIGH)
sec mass assignment Protect against mass assignment
6. Performance (MEDIUM)
No rule files exist yet for this category.
7. API Design (MEDIUM)
No rule files exist yet for this category.
Essential Patterns
Controller with Form Request
Form Request Class
Service Class Pattern
Eloquent Model
Migration Best Practices
Eager Loading
How to Use
Read individual rule files for detailed explanations and code examples:
Each rule file contains:
YAML frontmatter with metadata (title, impact, tags)
Brief explanation of why it matters
Bad Example with explanation
Good Example with explanation
Laravel 13 and PHP 8.3 specific context and references
Full Compiled Document
For the complete guide with all rules expanded: AGENTS.md