Skip to content

Commit

Permalink
Merge pull request #11 from someline/1.5
Browse files Browse the repository at this point in the history
1.5
  • Loading branch information
libern authored Mar 21, 2017
2 parents ea0ad71 + a8c02b3 commit c509b06
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Someline/Foundation/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,31 @@ function ip_to_country_iso_code($ip = null, $default_iso_code = 'US')
}

}

if (!function_exists('collection_paginate')) {

/**
* @param \Illuminate\Support\Collection $collection
* @param $perPage
* @param string $pageName
* @param null $page
* @return \Illuminate\Pagination\LengthAwarePaginator
*/
function collection_paginate(\Illuminate\Support\Collection $collection, $perPage, $pageName = 'page', $page = null)
{
$page = $page ?: \Illuminate\Pagination\Paginator::resolveCurrentPage($pageName);

$results = $collection->forPage($page, $perPage);

parse_str(request()->getQueryString(), $query);
unset($query[$pageName]);

return new \Illuminate\Pagination\LengthAwarePaginator($results, $collection->count(), $perPage, $page, [
'pageName' => $pageName,
'path' => \Illuminate\Pagination\LengthAwarePaginator::resolveCurrentPath(),
'query' => $query,
]
);
}

}

0 comments on commit c509b06

Please sign in to comment.