laravel
Avoid common Laravel mistakes — N+1 queries, mass assignment, cache gotchas, and queue serialization traps.
Installation
Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.
View source ↗GuidesSkill instructions
Quick Reference
| Topic | File |
|---|---|
| N+1 queries, eager loading, accessors, observers | eloquent.md |
| Validation, middleware order, dependency injection | controllers.md |
| Job serialization, retries, failed jobs | queues.md |
| Guards, policies, gates, Sanctum tokens | auth.md |
| XSS escaping, components, slots | blade.md |
| Commands, scheduling, tinker | artisan.md |
Critical Rules
- Eager load relationships —
with('posts')not lazy->postsin loop (N+1) -
preventLazyLoading()in dev AppServiceProvider — crashes on N+1, catches early -
env()only in config files — returns null afterconfig:cache -
$fillablewhitelist fields —$guarded = []allows mass assignment attacks -
find()returns null — usefindOrFail()to avoid null checks - Job properties serialize models as ID — re-fetched on process, may be stale/deleted
-
route:cacherequires controller routes — closures break cached routes -
DB::transaction()doesn't catchexit/timeout — only exceptions roll back -
RefreshDatabaseuses transactions — faster thanDatabaseMigrations -
{!! $html !!}skips escaping — XSS vector, use{{ }}by default - Middleware order matters — earlier middleware wraps later execution
-
requiredvalidation passes empty string — userequired|filledfor content -
firstOrCreatepersists immediately —firstOrNewreturns unsaved model - Route model binding uses
id— overridegetRouteKeyName()for slug
Examples
Read the usage examples in the source repository.
View source ↗Source history
- Indexed on
- 2026-03-11
- Index updated
- 2026-03-11
- Branch
- main
Index and sync dates describe this directory. View the source repository for code history.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!