title: Get average count of GroupBy Laravel
body: <p>I'm trying to make reviews system and  I want to get the average  of the count(id)  while using group by</p>
  
  <p>if I use count with group by  it works and I get  </p>
  
  <pre><code>return $comments  = Comment::select('rating',DB::raw('count(id)  as 
  total_reviews'))-&gt;where('product_id', $id)-&gt;where('shop_name', $shop)-
  &gt;groupBy('rating')-&gt;get();
  </code></pre>
  
  <p>results</p>
  
  <pre><code>  [
  {
  "rating": 1,
  "total_reviews": 1
  },
  {
  "rating": 2,
  "total_reviews": 2
  },
  {
  "rating": 3,
  "total_reviews": 2
  },
  {
  "rating": 4,
  "total_reviews": 6
  },
  {
  "rating": 5,
  "total_reviews": 61
  }
  ]
  </code></pre>
  
  <p>but when I add avg() I get an error</p>
  
  <pre><code>return $comments = Comment::select('rating',DB::raw('avg(count(id))
  as total_reviews'))-&gt;where('product_id', $id)-&gt;where('shop_name', $shop)-
  &gt;groupBy('rating')-&gt;get();
  </code></pre>
  
  <blockquote>
    <p>General error: 1111 Invalid use of group function (SQL: select
    <code>rating</code>, avg(count(id)) as total_reviews from <code>comments</code>.....</p>
  </blockquote>