lundi 26 mars 2018

Condition in eager loading Laravel

I have the following tables

  1. Purchases
  2. Products
  3. Sales

and following relations

  1. Purchase has many products
  2. Sale Has many products
  3. Product has many sales
  4. Product belongs to purchase

I want to get the sold products of a purchase. so my query was like this

$purchase = Purchases::with(['product','product.sale' => function ($query){
                return $query->where('status','complete');
            }])->find($request->id);

My question is the status is getting checked in the sales table? If it's not then is there any way without using raw query I can check the following condition in sales table?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire