Skip to content

Instantly share code, notes, and snippets.

@finagin
Created May 28, 2019 15:20
Show Gist options
  • Save finagin/be726b05606a93288b7a241470db7d60 to your computer and use it in GitHub Desktop.
Save finagin/be726b05606a93288b7a241470db7d60 to your computer and use it in GitHub Desktop.
Laravel divide collection
<?php
collect([])
->tap(static function (\Illuminate\Support\Collection $collection) {
$collection->macro('divide', function (int $chunks = 2) {
$size = ceil($this->count() / $chunks);
return $this->chunk($size);
});
})
->divide(3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment