laravel

Laravel Defaults

Core Laravel patterns and conventions

PHP
framework
Default
Used by 541 projects

Details

Language / Topic
phpPHP
Category
framework
Compatible Frameworks
laravel

Rules

balanced
- Use Eloquent relationships (`hasMany`, `belongsTo`, `morphMany`) with eager loading (`with()`) to prevent N+1 query problems.
- Use Form Request classes (`php artisan make:request`) for input validation — keep controllers thin by moving validation rules to dedicated classes.
- Use Laravel's service container and dependency injection in controller constructors — never use `app()` or `resolve()` in business logic.
- Use database migrations for ALL schema changes — never modify the database directly. Run `php artisan migrate` in CI/CD.
- Use queued jobs (`dispatch()`) for slow operations (emails, API calls, file processing) — never block the HTTP request cycle.
- Use Form Request classes for validation — keep controllers clean of validation logic.
- Use Eloquent relationships and scopes for query building. Avoid raw SQL in controllers.
- Use middleware for authentication, authorization, and cross-cutting concerns.
- Use config files and `.env` for configuration — never hardcode environment-specific values.
- Use Jobs and Queues for heavy operations (email, file processing, API calls).