Laravel Development
Workflow
- •Follow project conventions and Laravel 12 structure.
- •Use Boost docs search for framework or package questions.
- •Prefer framework-native patterns (Eloquent, Form Requests, policies, resources).
- •Prevent N+1 queries with eager loading and
Model::preventLazyLoading()in dev. - •Add
declare(strict_types=1);to all PHP files. - •Write or update Pest tests for behavior changes.
Database & Models
- •Prefer Eloquent relationships and query scopes over raw
DB::usage. - •Add indexes for frequently queried columns.
- •Use the
casts()method for cast definitions. - •Add cascade deletes where orphaned rows are invalid.
- •Ensure migrations include full column definitions when altering columns.
HTTP, Validation, Authorization
- •Use Form Request classes for validation; include custom messages.
- •Use policies/gates for authorization checks.
- •Prefer named routes and the
route()helper.
Testing (Pest)
- •Create tests with
php artisan make:test --pest. - •Use factories for model setup and avoid hardcoded dates.
- •Use
assertSuccessful(),assertForbidden(), etc. instead of raw status codes.
Performance & UX
- •Avoid lazy loading in non-production.
- •Eager load nested relationships and apply query limits for dashboards.
Lessons Learned
- •Append new lessons and do/don't guidance to
references/lessons.mdwith a date and short context.