title: laravel join with average of a column in another table
body: <p>I have a Food model and Review model. in my reviews table in database I have two columns : <code>food_id</code> and <code>rate</code>. Each user can rate foods and rate is an integer number between 1~5.</p>
  
  <p>I need to get all records in foods table and average of rate column in reviews where food_id is the id of each food.</p>
  
  <pre><code>$foods = Food::join('reviews', 'foods.id', '=', 'reviews.food_id')-&gt;select(
              'foods.*',
              'AVERAGE(reviews.rate) WHERE reviews.food_id = foods.id AS food_rate'
  )-&gt;get();
  </code></pre>
  
  <p>And of course this code will raise <code>SQLSTATE[42000]: Syntax error</code></p>
  
  <p>How can I join with average of a column in another table?</p>
  
  <pre><code>SELECT  foods.*, AVG(reviews.rate) AS food_rate
      FROM foods
          LEFT OUTER JOIN reviews
              ON reviews.food_id = foods.id
      GROUP BY foods.id
  </code></pre>
  
  <p>in fact this MYSQL code needs to be written with Laravel</p>