Created
July 22, 2018 20:16
-
-
Save spaceemotion/fba5f154d39f3cf9483e920868fe744c to your computer and use it in GitHub Desktop.
Revisions
-
spaceemotion created this gist
Jul 22, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ <?php namespace App\Providers; use Illuminate\Database\Eloquent\Builder; class DatabaseServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { // Chunking that does not break with where clauses Builder::macro('chunkSimple', function (int $size, callable $callable) { $page = 1; while (($chunk = $this->limit($size)->get())->count() >= $size) { if ($callable($chunk, $page++) === false) { return false; } } return true; }); } };