Skip to content

Instantly share code, notes, and snippets.

@zoparga
Created June 3, 2021 03:03
Show Gist options
  • Save zoparga/30447ccd195f3860298b7b71c2bc5512 to your computer and use it in GitHub Desktop.
Save zoparga/30447ccd195f3860298b7b71c2bc5512 to your computer and use it in GitHub Desktop.
Laravel collection or array paginator.
<?php
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