Created
June 23, 2015 08:53
-
-
Save zot24/401bb1be5539175c50ee to your computer and use it in GitHub Desktop.
Create your own LengthAwarePaginator with Laravel from a Collection
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
$page = $request->input('page') ?: 1; | |
$total = $collection->count(); | |
$start = ($page - 1) * $request->input('limit'); | |
$slice = $collection->slice($start, $request->input('limit'), true); | |
$paginator = new LengthAwarePaginator( | |
$slice->all(), | |
$total, | |
$request->input('limit'), | |
$request->input('page') ?: null, | |
[ | |
'path' => LengthAwarePaginator::resolveCurrentPath() | |
] | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment