jeudi 2 juillet 2020

Load relationships before foreach loop

I have a User model that does have many Networks. Each Network does have many Lists.
I have this code in the User model that is really slow:

foreach ($this->networks as $network) {
    if ($myCondition) {
        foreach ($network->lists()->get()->lists('id')->toArray() as $newId) {
            $ids[] = $newId;
        }
    }
}

I wonder if there is a way to load all lists of all networks before the 2 foreach loops.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire