Skip to content

Instantly share code, notes, and snippets.

@hlmn
Forked from simonhamp/AppServiceProvider.php
Created November 4, 2017 04:03
Show Gist options
  • Save hlmn/d18c7181573801516a15027548d01557 to your computer and use it in GitHub Desktop.
Save hlmn/d18c7181573801516a15027548d01557 to your computer and use it in GitHub Desktop.
A pageable Collection implementation for Laravel
<?php
namespace App\Support;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection as BaseCollection;
class Collection extends BaseCollection {
public function paginate( $perPage, $total = null, $page = null, $pageName = 'page' )
{
$page = $page ?: LengthAwarePaginator::resolveCurrentPage( $pageName );
return new LengthAwarePaginator( $this->forPage( $page, $perPage ), $total ?: $this->count(), $perPage, $page, [
'path' => LengthAwarePaginator::resolveCurrentPath(),
'pageName' => $pageName,
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment