Support the ongoing development of →
Last updated by @athar-jamil-raihan 1 week ago.

The query $result = Serial::where('date','2022-05-11')->with(['patient.village'])->get() will result in a collection Serial where each item has a patient and each patient has a village (if they exist).

$serials = Serial::where('date','2022-05-11')->with(['patient.village'])->get()
foreach ($serials as $serial) P

First check your FK are correct between models and that the return relation is not inverted. Second, be careful to always select the FK. if you're doing DB query optimizations.

As an extra TIP: I prefer to write my eager loading like $serials = Serial::with(['patient' => function ($q) { $q->with(['village']); }]) ->where('date', '2022-05-11') ->get(); this way you can add extra where conditions in your eager/lazy load queries


Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 - All rights reserved.