PHP-089 / 中级
Eloquent 嵌套关联加载导致 N+1/DoS
为什么存在问题?
通过请求参数决定加载深度会产生大量查询。
如何修复
php
$allowed = ['posts', 'profile'];
User::with(array_intersect((array) $request->input('relations'), $allowed))->get();