Cursor Rules for
Laravel

This rule explains Laravel conventions and best practices for backend development.
Back to rules
Type
Backend
Language(s)
PHP
Stats
529 views
22 copies
21 downloads
Contributors
Venelin Kochev
Venelin Kochev
Venelin Kochev
laravel.mdc
---
description: This rule explains Laravel conventions and best practices for backend development.
globs: **/*.php
alwaysApply: false
---

# Laravel rules

- Use `php artisan make:{option}` to create models, migrations, controllers, etc.
- `app\Console\Kernel.php` does not exist in Laravel 11+. If the file is not present, use the the [app.php](mdc:bootstrap/app.php) file for related configurations.
- In Laravel 11+ commands created in `app\Console\Commands\` are automatically registered and available to use.
- Add environment variables to config files and avoid using env variables directly in the code. For example `config('app.name')` instead of `env('APP_NAME')`.
- Avoid N+1 queries by using eager loading or batch loading. Examples:

```php
$users = User::with('posts')->get();
$posts = Post::whereIn('user_id', $users->pluck('id'))->get();
```

- Prefer soft deletes for models using the `SoftDeletes` trait:

```php
class User extends Model
{
    use SoftDeletes;
}
```
Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later