title: Laravel: how to get average on nested hasMany relationships (hasManyThrough)
body: <p>I have three tables:</p>
  
  <pre><code>products:   id|name|description|slug|category_id|...
  reviews:    id|product_id|review_text|name|email|...
  review_rows id|review_id|criteria|rating
  </code></pre>
  
  <p>the review table stores the review text, writer of the review and has a foreign product_id key. The review_rows table stores the ratings for different criteria like:</p>
  
  <pre><code>----------------------------------------
  | id |  criteria  | rating | review_id |
  ----------------------------------------
  |  1 |  price     | 9      | 12        |
  ----------------------------------------
  |  2 |  service   | 8      | 12        |
  ----------------------------------------
  |  3 |  price     | 6      | 54        |
  ----------------------------------------
  |  4 |  service   | 10     | 54        |
  ----------------------------------------
  </code></pre>
  
  <p>review rows are linked to the review table with the review_id foreign key. I've set up my model relationships like this:</p>
  
  <pre><code>Product   -&gt; hasMany   -&gt; Review
  Review    -&gt; belongsTo -&gt; Product
  Review    -&gt; hasMany   -&gt; ReviewRow
  ReviewRow -&gt; belongsTo -&gt; Review
  </code></pre>
  
  <p>Now I would like to display the average rating for a product on my category and product pages. How can I achieve this?</p>
  
  <p>I need to sum and average all the reviewRows per review and then sum and average all of those for each review to end up with the overall rating for that product. Is this possible via Eloquent or do I need a different solution or a different database design/structure?</p>
  
  <p>Thanks in advance!</p>