まえおき laravelでリレーションを張ったモデルを扱っているとN+1問題に遭遇してしまいます。 ググっても動的プロバティは遅延ロードされる、eager loadは熱心なロードです、ってなんやねんって思ったのは私だけでしょうか。 とりあえずwith()使っとけばいいんでしょ?となんとなくコードを書いてきたので、そろそろ仕組みを知りたいなあと思ったのでコードリーディングの旅に出たのであります。 laravelのバージョンは5.8です。 設定 モデルはユーザーと本があり、1:多で結びつきます。 リレーションは以下のように設定しておきます。