PHP-089 / 중급
Eloquent 중첩 관계 로딩으로 N+1/DoS
왜 문제가 될까요?
요청 파라미터로 로딩 깊이를 정하면 수많은 쿼리가 발생한다.
이렇게 수정하세요
php
$allowed = ['posts', 'profile'];
User::with(array_intersect((array) $request->input('relations'), $allowed))->get();