title: Laravel sum join with condition
body: <p>I have products, warehouses, transactions and transaction_details table.</p>
  <pre><code>$p = Product::leftJoin('transaction_details', 'products.id', '=' ,'transaction_details.product_id')
      -&gt;leftJoin('transactions', 'transaction_details.transaction_id', '=', 'transactions.id')
      -&gt;leftJoin('keep_details', 'products.id', '=', 'keep_details.product_id')
      -&gt;selectRaw(
                      'products.id,products.product_name productName, products.category_id,
                      products.sub_category_id, IFNULL(sum(transaction_details.quantity), 0) as totalQty,
                      products.package_qty, IFNULL(sum(keep_details.quantity), 0) as totalKeep'
                  )
      -&gt;groupBy('id','productName','category_id', 'sub_category_id', 'package_qty')
      -&gt;get();
      return new StockCollection($p);
  </code></pre>
  <p>By using the above query I am able to get all the products quantity as expected. But in some cases, I just want the stock quantity of a specific warehouse. I've tried this by added where clause of warehouse Id which is related to the transactions table.</p>
  <pre><code>$p = Product::leftJoin('transaction_details', 'products.id', '=' ,'transaction_details.product_id')
      -&gt;leftJoin('transactions', 'transaction_details.transaction_id', '=', 'transactions.id')
      -&gt;leftJoin('keep_details', 'products.id', '=', 'keep_details.product_id')
      -&gt;selectRaw(
                      'products.id,products.product_name productName, products.category_id,
                      products.sub_category_id, IFNULL(sum(transaction_details.quantity), 0) as totalQty,
                      products.package_qty, IFNULL(sum(keep_details.quantity), 0) as totalKeep'
                  )
      -&gt;where('transactions.warehouse_id', 1) // add this line ####################
      -&gt;groupBy('id','productName','category_id', 'sub_category_id', 'package_qty')
      -&gt;get();
      return new StockCollection($p);
  </code></pre>
  <p>There aren't any errors but It not showing all the products as I expected, that's because some product does not contain any transaction in the warehouse yet, But I want to show all products even when it does not has any transactions yet just showing 0 quantity. I know that's not too complicated but I am just a noob in this, therefore How can I accomplish that? Thank you in advance...</p>