mercredi 26 octobre 2016

Laravel: dynamic property loading when not required in loop

I have customer model and product model joined by subscriptions table. When i run something like $customers = Customer::with('products' => function($query) { $query->where('somecondition');});

And if i loop over customers like :

    foreach ($customers as $customer){
      foreach($customer->products as $product) {
        # do something
      }
    }

It loads the entire products of the customer ignoring the condition above by using dynamic property.. How to fix this?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2fgqGwp
via IFTTT

Aucun commentaire:

Enregistrer un commentaire