title: Laravel 4 - Return average score from within model?
body: <p>I'd like to return the average score for game reviews in my database. I am building my site with Laravel 4.</p>
  
  <p>TABLE STRUCTURE:</p>
  
  <pre><code>GAMES (id, title, etc)
  REVIEWS (game_id, user_id, score, etc)
  </code></pre>
  
  <p>CONTROLLER:</p>
  
  <pre><code>public function singleGame($id)
  {
      $game = Game::find($id);
  
      if ($game)
      {
          return View::make('game')-&gt;with('game', $game);
      }
      else
      {
          return Redirect::to('/');
      }
  }
  </code></pre>
  
  <p>My thought is to hopefully return the average score for a game through $game->average in my view, but I've been unable to produce the desired result through fiddling with my Game model.</p>
  
  <p>GAME MODEL:</p>
  
  <pre><code>public function scores()
  {
      return $this-&gt;hasMany('Review')-&gt;avg('score');
  }
  </code></pre>
  
  <p>I've tried a number of methods available to the query builder, but I'm still learning the ropes when it comes to Laravel/PHP, so I'm kinda stuck. Perhaps I should be approaching the problem differently?</p>
  
  <p>Thanks.</p>