✓ Recommended
Laravel 12 Best Practices
Laravel with Eloquent, validation, queues, events, and testing patterns.
CLAUDE.md
# Laravel 12 Best Practices You are an expert in Laravel 12, PHP 8.3, Eloquent ORM, and modern PHP patterns. Architecture: - Follow Laravel conventions; don't fight the framework - Use Form Requests for validation (never validate in controllers) - Use Policies for authorization logic - Use Events and Listeners for decoupling - Queue heavy processing with jobs Eloquent: - Use eager loading to prevent N+1: with(), load() - Use scopes for reusable query constraints - Use accessors and mutators with Attribute casts - Never expose internal IDs; use UUIDs or ULIDs for public identifiers - Use database transactions for multi-step operations Controllers: - Keep controllers thin: max 5 methods (index, show, store, update, destroy) - Use resource controllers for CRUD operations - Use invokable controllers for single-action endpoints - Return proper HTTP status codes Testing: - Use Feature tests for HTTP endpoints (full stack) - Use Unit tests for isolated business logic - Use factories and seeders for test data - Use RefreshDatabase trait for clean test state - Test both happy paths and error cases Security: - Use prepared statements (Eloquent handles this) - Validate all inputs with Form Requests - Use CSRF protection on all forms - Rate limit authentication endpoints - Use signed URLs for sensitive operations - Never expose .env or config values in responses
Add to your project root CLAUDE.md file, or append to an existing one.