My Cursor Rules for Laravel Projects

Tutorial last revisioned on July 10, 2025

Let me share the Cursor rules I use as "User rules". I'm planning to update this article with more changes in the future.

You can place these rules in Cursor Settings, like this:

But, of course, Cursor UI may change in the future, which I will also update in this article.

Last updated: July 10, 2025

## General code instructions
 
- Don't generate code comments above the methods or code blocks if they are obvious. Generate comments only for something that needs extra explanation for the reasons why that code was written
- When changing the code, don't comment it out, unless specifically instructed. Assume the old code will stay in Git history.
 
---
 
## Laravel/PHP instructions
 
- For DB pivot tables, use correct alphabetical order, like "project_role" instead of "role_project"
- I am using Laravel Herd locally, so always assume that the main URL of the project is `http://[folder_name].test`
- **Eloquent Observers** should be registered in Eloquent Models with PHP Attributes, and not in AppServiceProvider. Example: `#[ObservedBy([UserObserver::class])]` with `use Illuminate\Database\Eloquent\Attributes\ObservedBy;` on top
- When generating Controllers, put validation in Form Request classes
- Aim for "slim" Controllers and put larger logic pieces in Service classes
- Use Laravel helpers instead of `use` section classes whenever possible. Examples: use `auth()->id()` instead of `Auth::id()` and adding `Auth` in the `use` section. Another example: use `redirect()->route()` instead of `Redirect::route()`.
- In PHP, use `match` operator over `switch` whenever possible
 
---
 
## Use Laravel 11+ skeleton structure
 
- **Service Providers**: there are no other service providers except AppServiceProvider. Don't create new service providers unless absolutely necessary. Use Laravel 11+ new features, instead. Or, if you really need to create a new service provider, register it in `bootstrap/providers.php` and not `config/app.php` like it used to be before Laravel 11.
- **Event Listeners**: since Laravel 11, Listeners auto-listen for the events if they are type-hinted correctly.
- **Console Scheduler**: scheduled commands should be in `routes/console.php` and not `app/Console/Kernel.php` which doesn't exist since Laravel 11.
- **Middleware**: whenever possible, use Middleware by class name in the routes. But if you do need to register Middleware alias, it should be registered in `bootstrap/app.php` and not `app/Http/Kernel.php` which doesn't exist since Laravel 11.
- **Tailwind**: in new Blade pages, use Tailwind and not Bootstrap, unless instructed otherwise in the prompt. Tailwind is already pre-configured since Laravel 11, with Vite.
- **Faker**: in Factories, use `fake()` helper instead of `$this->faker`.
- **Policies**: Laravel automatically auto-discovers Policies, no need to register them in the Service Providers.
 
---
 
## Using PHP Services in Controllers
 
- If Service class is used only in ONE method of Controller, inject it directly into that method with type-hinting.
- If Service class is used in MULTIPLE methods of Controller, initialize it in Constructor.
- Use PHP 8 constructor property promotion. Don't create empty Constructor method if it doesn't have any parameters.
 
---
 
## Filament Rules
 
- When using Filament 4, generate resources `php artisan make:filament-resource` using `--view` flag, to avoid extra question in the Terminal.

You can learn more from my video course: Cursor for Laravel Projects: Crash Course


History of Updates

  • July 10, 2025: added a section "Filament rules" with --view flag to be used in Filament 4
  • July 5, 2025: added five rules - how Observers should be registered, validation in Form Requests, "slim" Controllers with Service classes, using Laravel helpers like redirect() instead of classes in the use section, and use match over switch in PHP
  • July 1, 2025: added the info that I'm using Laravel Herd locally so website URL is http://[folder].test
  • July 1, 2025: removed all instructions related to php artisan make commands, as I switched to "Auto-run" mode (with restriction from deleting files, of course) where I don't even see/approve those commands
  • June 30, 2025: added "When generating Models and Migrations, do it in one Artisan command: php artisan make:model -m instead of doing separate make:model and make:migration" after I had to manually approve 2x commands (auto-run didn't work for some reason)
  • June 30, 2025: removed the instruction to use Filament 3 syntax, as Filament 4 Beta is out, and I will use v3/v4 depending on a project.
  • June 27, 2025: added "Don't create empty Constructor method if it doesn't have any parameters" after Cursor generated a Service class with empty and useless Constructor.

No comments or questions yet...

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 80 courses
  • 96 long-form tutorials
  • access to project repositories
  • access to private Discord

Recent New Courses