Created
June 27, 2018 07:51
-
-
Save Ellrion/862f2563715f95d5e5ba1e88329c5fb3 to your computer and use it in GitHub Desktop.
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 characters
<?php | |
use Illuminate\Support\Collection; | |
Collection::macro('crossMerge', function (Collection $collection) { | |
return $this->reduce(function (Collection $result, $item) use ($collection) { | |
$result->push($item); | |
if ($collection->isNotEmpty()) { | |
$result->push($collection->shift()); | |
} | |
return $result; | |
}, new Collection())->concat($collection); | |
}); | |
Collection::macro('paginate', function ($perPage = 25, $pageName = 'page', $currentPage = null) { | |
$currentPage = $currentPage ?: \Illuminate\Pagination\Paginator::resolveCurrentPage($pageName); | |
$currentPage = $currentPage ?: 1; | |
return new \Illuminate\Pagination\LengthAwarePaginator( | |
$this->forPage($currentPage, $perPage)->values(), | |
$this->count(), | |
$perPage, | |
$currentPage, | |
['path' => \Illuminate\Pagination\Paginator::resolveCurrentPath()] | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment