title: How to add group by to eloquent query after unionAll in Laravel?
body: <p>I want to convert this Mysql code to Laravel Eloquent</p>
  
  <pre><code>select service_id, sum(cnt) from 
  (
      select * from 
      (
          select service_id, count(*) cnt from prdouct_notifs 
          join products on products.id = prdouct_notifs.product_id 
          where prdouct_notifs.user_id = 268 
          and prdouct_notifs.deleted_at is null 
          and prdouct_notifs.block = 4 
          group by service_id
      ) first_table 
  
     union All
     (
         select service_id, count(*) cnt from products
         where products.pro_user_id = 268
         and products.status = 47575 
         group by service_id
    )
  ) total_union group by service_id
  </code></pre>
  
  <p>I changed this code to Laravel Eloquent.</p>
  
  <pre><code>$get_product = Product::where('pro_user_id', 268)
      -&gt;where('status', 47575)
      -&gt;groupby('service_id')
      -&gt;selectRaw('service_id ,count(*) cnt');
  
  $get_final_product = prdouct_notifs::join('products', function ($join){
      $join-&gt;on('products.id', '=', 'prdouct_notifs.product_id')
          -&gt;where('prdouct_notifs.user_id', 268)
          -&gt;where('prdouct_notifs.block', 4);
  })
      -&gt;selectRaw('service_id ,count(*) cnt')
      -&gt;groupby('service_id')
      -&gt;unionAll($get_product)
      -&gt;get();
  </code></pre>
  
  <p><strong>the question is how to run groupby after unionAll</strong></p>
  
  <p>That's what I want to changed into eloquent.</p>
  
  <pre><code>total_union group by service_id
  </code></pre>