🔴

Cursor Rules for Laravel + PHP

Laravel PHP framework with Eloquent and Blade

PHPLaravelEloquentBlade
.cursorrules
# Role
You are an expert Laravel developer following Laravel conventions and best practices.

# Tech Stack
- PHP 8.3+
- Laravel 11
- Eloquent ORM
- Blade Templates
- Livewire

# Code Conventions
- Follow Laravel naming conventions: PascalCase models, snake_case DB columns.
- Use Eloquent ORM for all database operations.
- Use form requests for validation logic.
- Use resource controllers for REST endpoints.
- Use Laravel's built-in authentication scaffolding.
- Use service classes for complex business logic.
- Use Laravel queues for background jobs.
- Use Blade components for reusable UI elements.
- Use migrations and seeders for database management.

# Code Style Preferences
- Use TypeScript strict mode. Define types for all variables, parameters, and return values.
- Never use the `any` type. Use `unknown` if the type is truly uncertain, then narrow it.
- Use `const` by default. Only use `let` when reassignment is needed. Never use `var`.
- Always handle errors explicitly. Use try/catch for async operations. Never silently swallow errors.
- Use early returns (guard clauses) to reduce nesting and improve readability.
- Use descriptive, meaningful names for variables, functions, and classes. Avoid abbreviations.
- Keep functions small and focused. Each function should do one thing. Aim for under 50 lines.

# What to Avoid
- Do not write raw SQL queries — use Eloquent or Query Builder.
- Do not put business logic in controllers — use services.
- Do not use `env()` outside of config files.
- Do not skip validation — always use form requests.

About Cursor Rules for Laravel + PHP

The .cursorrules file helps Cursor understand your Laravel + PHP project's conventions, tech stack, and coding standards. This ensures the AI generates code that matches your team's style and follows best practices for Laravel.

This preset includes rules for:

  • Follow Laravel naming conventions: PascalCase models, snake_case DB columns.
  • Use Eloquent ORM for all database operations.
  • Use form requests for validation logic.
  • Use resource controllers for REST endpoints.
  • Use Laravel's built-in authentication scaffolding.

How to use this file

  1. Click Copy or Download above.
  2. Place the .cursorrules file in your project's root directory.
  3. Cursor will automatically detect and apply these rules.

Get Laravel + PHP Rules for Other IDEs

Other Cursor Presets