samedi 4 février 2017

Left joining in Laravel

I am building my app and I needed to use leftJoin in laravel

I prepared a query in database and it works fine.

SELECT sp.id, ssp.sale_id, ssp.product_id FROM store_products sp 
LEFT JOIN store_sale_products ssp ON sp.id = ssp.product_id 
WHERE ssp.sale_id IS NULL AND sp.store_id = 1

Now I am implementing this query on laravel and I tried this

$nosaleproducts = Store_product::leftJoin('store_sale_products','store_products.id','=','store_sale_products.product_id')
        ->where('store_sale_products.sale_id','IS','NULL')
        ->where('store_products.store_id','=',session::get('store_id'))
        ->get(['store_products.id','store_products.product_name']);

But this gets me no results. Can anyone specify what is wrong with my query?



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

Aucun commentaire:

Enregistrer un commentaire