Skip to content

Instantly share code, notes, and snippets.

@shah253kt
Forked from vluzrmos/paginate.php
Created January 8, 2019 23:10
Show Gist options
  • Save shah253kt/68f3f86a5806a9acfdb696bb4d371ca8 to your computer and use it in GitHub Desktop.
Save shah253kt/68f3f86a5806a9acfdb696bb4d371ca8 to your computer and use it in GitHub Desktop.
Laravel Paginate Collection or Array
<?php
/**
* Gera a paginação dos itens de um array ou collection.
*
* @param array|Collection $items
* @param int $perPage
* @param int $page
* @param array $options
*
* @return LengthAwarePaginator
*/
public function paginate($items, $perPage = 15, $page = null, $options = [])
{
$page = $page ?: (Paginator::resolveCurrentPage() ?: 1);
$items = $items instanceof Collection ? $items : Collection::make($items);
return new LengthAwarePaginator($items->forPage($page, $perPage), $items->count(), $perPage, $page, $options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment