Since it was rejected as pull request: laravel/framework#20985
Ok, then I've found this: https://github.com/spatie/laravel-collection-macros (eachCons)
Since it was rejected as pull request: laravel/framework#20985
Ok, then I've found this: https://github.com/spatie/laravel-collection-macros (eachCons)
\Illuminate\Support\Collection::macro('sliceConsecutive', function ($size) | |
{ | |
if ($size <= 0) { | |
return new static; | |
} | |
if ($size >= $this->count()) { | |
return new static([$this]); | |
} | |
$chunks = []; | |
for ($i = 0; $i <= $this->count() - $size; $i++) { | |
$chunks [] = $this->slice($i, $size)->values(); | |
} | |
return new static($chunks); | |
}); |