title: laravel 4 - how to Limit (Take and Skip) for Eloquent ORM?
body: <h2>TL;DR</h2>
  
  <p>Can you limit an Eloquent ORM query like using <code>take()</code> and <code>skip()</code> so that the resulting mysql query is also limited, and it doesn't have to return the entire dataset?</p>
  
  <p>If so, how would you modify:</p>
  
  <pre><code>$test = User::find(1)-&gt;games-&gt;toArray();
  </code></pre>
  
  <p>To include <code>limit 3 offset 2</code>?</p>
  
  <hr>
  
  <h2>Tables:</h2>
  
  <pre><code>users       games           userGames
  -- id       -- id           -- user_id
  -- name     -- name         -- game_id
              -- steam_id
  </code></pre>
  
  <h2>Models:</h2>
  
  <pre><code>class User extends Eloquent {
      public function games() {
          return $this-&gt;belongsToMany('Game', 'userGames', 'user_id', 'game_id');
      }
  }
  
  class Game extends Eloquent {
      public function users() {
          return $this-&gt;belongsToMany('User', 'userGames', 'user_id', 'game_id');
      }
  }
  </code></pre>
  
  <hr>
  
  <h2>Limit in Query Builder</h2>
  
  <p>Using the regular Laravel <strong>Query Builder</strong> I can get all <code>games</code> that belong to <code>user</code> of id 1, and limit the result with <code>take()</code> and <code>skip()</code>:</p>
  
  <pre><code>$test = DB::table('games')
      -&gt;join('userGames', 'userGames.game_id', '=', 'games.id')
      -&gt;where('userGames.user_id', '=', '1')-&gt;take(3)-&gt;skip(2)-&gt;get();
  </code></pre>
  
  <p>By listening to the <code>illuminate.query</code> event I can see that the query generated by this is:</p>
  
  <pre><code>select * from `games`
  inner join `userGames`
  on `userGames`.`game_id` = `games`.`id`
  where `userGames`.`user_id` = ?
  limit 3 offset 2
  </code></pre>
  
  <h2>Limit in Eloquent ORM</h2>
  
  <p>When I try to recreate the same query with Eloquent:</p>
  
  <pre><code>$test = User::find(1)-&gt;games-&gt;take(2)-&gt;toArray();
  </code></pre>
  
  <p>I'm able to use <code>take</code> but adding <code>skip</code> causes an error. Also the resulting query does not actually contain the limit:</p>
  
  <pre><code>select `games`.*, `userGames`.`user_id` as `pivot_user_id`,
  `userGames`.`game_id` as `pivot_game_id` from `games`
  inner join `userGames`
  on `games`.`id` = `userGames`.`game_id`
  where `userGames`.`user_id` = ?
  </code></pre>
  
  <p>So it seems that the entire result is being queried first, which is not ideal when dealing with large data sets.</p>
  
  <hr>
  
  <h2>Question:</h2>
  
  <p>Is it possible to limit an Eloquent ORM query so that at the MYSQL Query level it also limits the result, equivalent to <code>limit 3 offset 2</code>?</p>