mercredi 30 août 2017

How to Preform a where query on a relation table Laravel?

I have an order with orderLines and an orderLine has a product.

I want to only retrieve orderLines where product type != Partkit. So i want to query the Product table where type != Partkit.

How do i do this? Order query:

$order = Order::with('orderLines.product')->where('user_id',Auth()->user()->id)->where('is_order','0')->first();

What i tried:

$order = Order::with('orderLines.product')->whereHas('orderLines.product', function($query) {
            $query->where('type','!=', 'Partkit');
        })->where('user_id',Auth()->user()->id)->where('is_order','0')->first();

this allways return NULL which is not what i want and isn't correct...

any help is appreciated



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire