Skip to content

Instantly share code, notes, and snippets.

@zot24
Created June 23, 2015 08:53
Show Gist options
  • Save zot24/401bb1be5539175c50ee to your computer and use it in GitHub Desktop.
Save zot24/401bb1be5539175c50ee to your computer and use it in GitHub Desktop.
Create your own LengthAwarePaginator with Laravel from a Collection
$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