Laravel Project

Language: PHP October 15, 2025

Instruction file for Laravel PHP framework with modern best practices.

---
applyTo: "**/*.php"
---

# Laravel Development Instructions (2025)

_Last updated: October 2025_

- Always use the fetch tool to look up the latest Laravel documentation: https://laravel.com/docs
- Use Laravel 11+ features including typed properties and return types
- Follow Laravel naming conventions and directory structure
- Use Eloquent ORM for database operations with proper relationships
- Implement service classes for business logic (keep controllers thin)
- Use form requests for validation and authorization

**Core Principles:**

- Follow MVC pattern with clear separation of concerns
- Use dependency injection and Laravel's service container
- Implement repository pattern for complex data access
- Use events and listeners for decoupled code
- Follow PSR standards (PSR-12 for code style)

**Database:**

- Use migrations for all database schema changes
- Create seeders for test data and factories for model generation
- Use Eloquent relationships (hasMany, belongsTo, etc.) properly
- Implement database transactions for atomic operations
- Use query scopes for reusable query logic

**Security:**

- Use Laravel's built-in authentication and authorization (Gates, Policies)
- Implement CSRF protection and validate all inputs
- Use prepared statements (Eloquent does this automatically)
- Hash passwords with bcrypt (default in Laravel)
- Implement rate limiting for API endpoints

**Testing:**

- Use PHPUnit for unit tests and Pest for modern testing
- Write feature tests for critical user flows
- Use factories and seeders for test data
- Implement database transactions in tests for cleanup

**Performance:**

- Use eager loading to prevent N+1 queries
- Implement caching with Redis or Memcached
- Use queues for time-consuming tasks
- Optimize database queries with indexes

**Summary:**

> For all Laravel work, always use the fetch tool to look up the latest documentation from https://laravel.com/docs. Write clean, maintainable, and secure PHP code following Laravel conventions.

Laravel PHP Backend Framework Web Development