title: Laravel groupBy column and add totals based on Quantity column
body: <p>I have a pivot table in Laravel (order_product) which records each product which belongs to an order.</p>
  
  <p>I use the following columns "<strong>order_id, product_id, qty</strong>"</p>
  
  <p>If I use </p>
  
  <pre><code>DB::table('order_product')-&gt;selectRaw('*, count(*)')-&gt;groupBy('product_id');
  </code></pre>
  
  <p>I get the count of each product occurrence. </p>
  
  <p>Some products, however, occur more than once in an order. How do I multiply each product by the <strong>qty</strong> column and then group by <strong>product_id</strong> and count them together?</p>
  
  <p>At the end I need to get the total count of all orders grouped by product. </p>
  
  <p><strong>EDIT</strong>
  Here's my database table</p>
  
  <p><a href="https://i.stack.imgur.com/clUme.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/clUme.png" alt="enter image description here"></a></p>
  
  <p>Desired output:</p>
  
  <p>Product (ID = 30) occurs <strong>5</strong> times in the table, from 5 different orders. The product total multiplied by the quantity columns would equal to <strong>13</strong></p>