zot24
6/23/2015 - 8:53 AM

Create your own LengthAwarePaginator with Laravel from a Collection

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()
    ]
);