laravel
Avoid common Laravel mistakes — N+1 queries, mass assignment, cache gotchas, and queue serialization traps.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
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
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-03-11
- 索引更新时间
- 2026-03-11
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!