一键导入
laravel-eloquent-relationships
Define clear relationships and load data efficiently; prevent N+1, use constraints, counts/sums, and pivot syncing safely
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Define clear relationships and load data efficiently; prevent N+1, use constraints, counts/sums, and pivot syncing safely
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | laravel:eloquent-relationships |
| description | Define clear relationships and load data efficiently; prevent N+1, use constraints, counts/sums, and pivot syncing safely |
Model relationships express your domain; load only what you need.
# Typical loading
Post::with(['author', 'tags'])->withCount('comments')->paginate(20);
# Constrained eager loading
User::with(['posts' => fn($q) => $q->latest()->where('published', true)])->find($id);
# Pivot ops (many-to-many)
$post->tags()->sync([1,2,3]); // atomic replace
$post->tags()->syncWithoutDetaching([4]);
# Chunking large reads
Order::where('status', 'open')->lazy()->each(fn($o) => ...);
laravel:performance-eager-loading for N+1 detection and measurementwhereHas() / has() to filter by related existencewithCount, withSum, withMax for simple aggregates#[DateFormat('Y-m-d')] and #[WithoutTimestamps] are available (see laravel:php-attributes)Build AI features with the first-party Laravel AI SDK (Laravel 13+); agents, embeddings, images, audio, and tool calling with provider-agnostic APIs
Use API Resources with pagination and conditional fields; keep response shapes stable and cache-friendly
Compose UIs with Blade components, slots, and layouts; keep templates pure and testable
Request effective code reviews—specify focus areas, provide context, ask for architectural feedback, reference Laravel conventions
Practical daily checklist for Laravel projects; bring services up, run migrations, queues, quality gates, and tests
Create effective debugging prompts—include error messages, stack traces, expected vs actual behavior, logs, and attempted solutions