Sometimes, you will need to process thousand and thousand of records. You know that those operations are very heavy for your RAM, but Eloquent has a useful method to chunk query results in blocks to optimize your load.

  Apphouse::chunk(200, function($houses)
      foreach ($houses as $house)
          // heavy operations on the houses here...

The first parameter defines the size of the block you want to use. In this case, we will load 200 results, process them, unload them, and repeat the same thing with the next 200.

The second parameter is a closure that defines what to do with that chunk: the houses closure parameter is the returned collection of records.