Production-Ready Rule
•
app/**/*.php, routes/**/*.php, database/**/*.php
Laravel 11 & Modern PHP 8.3 .cursorrules (.mdc)
Modern .cursorrules and .cursor/rules/*.mdc configuration for Laravel 11 and PHP 8.3. Enforce Form Request validation, API Resources, strict Eloquent query optimization, and Pest testing.
.cursor/rules/laravel-php.mdc
---
description: Laravel 11 and modern PHP 8.3 backend engineering standards
globs: app/**/*.php, routes/**/*.php, database/**/*.php
alwaysApply: false
---
# Laravel 11 & PHP 8.3 Standards
## Controller & Request Validation
- Never validate requests directly inside controllers with $request->validate().
- Always extract validation into dedicated Form Request classes: `php artisan make:request`.
- Format API outputs using JsonResource / ResourceCollection classes; never return raw Eloquent models directly.
## Eloquent Discipline & Performance
- Prevent lazy loading in local development: call `Model::preventLazyLoading()` in AppServiceProvider.
- Always eager load relations with `with([...])` to prevent N+1 query loops.
- Use typed properties and PHP 8.3 constructor property promotion across all classes.
## Testing & Quality
- Write tests using Pest PHP for all feature endpoints.
- Group complex business mutations into single-purpose Action classes (`app/Actions`).
⭐
Using this rule in your open-source project? Reference in your README:
https://cursor.pacebowl.com/rules/laravel-php
Frequently Asked Questions & Implementation Notes
Why are Form Requests mandated over inline controller validation?
Dedicated Form Requests encapsulate validation rules and authorization logic in reusable classes, keeping controller methods slim and single-responsibility.
How does it ensure high-performance Eloquent queries?
It enforces eager loading via with() and instructs developers to enable Model::preventLazyLoading(), throwing hard exceptions whenever un-eager-loaded queries execute.