laravel/framework — pull request #5110 by timgws (2014-07-17 08:21:41+00:00)
Title: Allow chunk to exit when the closure returns false

When looping through all of the different rows returned by an SQL statement using a chunk closure, you should be able to specify to Builder that you wish to no longer continue processing chunks by simply returning false inside the closure, without having to exit.

### Usage Example

DB::table('download_files')
->where('downloaded', 0)
->chunk(5000, function($urls) use (&$post, &$loop, $time_queries, $time_started) {

foreach($urls as $url) {
Download::file($url->path, $url->filename);

// only allow to run for 20 seconds...
if ($time_started+20 > microtime(true)) {
return false
}
}

})