title: How to get database resource instead of array from Laravel Query Builder?
body: <p>When I execute a PDO statement, internally a result set is stored, and I can use <code>-&gt;fetch()</code> to get a row from the result.</p>
  
  <p>If I wanted to convert the entire result to an array, I could do <code>-&gt;fetchAll()</code>.</p>
  
  <p>With Laravel, in the <a href="http://laravel.com/docs/queries#selects" rel="nofollow">Query Builder docs</a>, I <strong>only</strong> see a way to get an array result from executing the query.</p>
  
  <pre><code>// example query, ~30,000 rows
  
  $scores = DB::table("highscores")
              -&gt;select("player_id", "score")
              -&gt;orderBy("score", "desc")
              -&gt;get();
  
  var_dump($scores);
  // array of 30,000 items...
  // unbelievable ...
  </code></pre>
  
  <p>Is there any way to get a result set from Query Builder like PDO would return? Or am I forced to wait for Query Builder to build an entire array before it returns a value ?</p>
  
  <p>Perhaps some sort of <code>-&gt;lazyGet()</code>, or <code>-&gt;getCursor()</code> ?</p>
  
  <hr>
  
  <p>If this is the case, I can't help but see Query Builder is an extremely short-sighted tool. Imagine a query that selects 30,000 rows. With PDO I can step through row by row, one <code>-&gt;fetch()</code> at a time, and handle the data with very little additional memory consumption.</p>
  
  <p>Laravel Query Builder on the other hand? "Memory management, huh? It's fine, just load 30,000 rows into one big array!"</p>
  
  <hr>
  
  <p><strong>PS</strong> yes, I know I can use <code>-&gt;skip()</code> and <code>-&gt;take()</code> to offset and limit the result set. In most cases, this would work fine, as presenting a user with 30,000 rows is not even usable. If I want to generate large reports, I can see PHP running out of memory easily.</p>