How do I manually create a Paginator in 5

Hi I've looking round for a while now but cant figure this out how do How do I manually create a Paginator instance in version 5 I used to be able to do $paginator = Paginator::make($items, $totalItems, $perPage); but this no longer works any help really appreciated

jimgwhit replied 3 years ago

Type in search box laravel 5 pagination, There's a post with about 14 responces that will walk you through.
The post is so good a 5 year old clild could figure it out. Please search first. In fact here you go:

Ardakilic replied 2 years ago

Try this:

Route::get('hede', function(){
    $paginator = new Illuminate\Pagination\LengthAwarePaginator(
        range(1,500), //a fake range of total items, you can use range(1, count($collection))
        500, //count as in 1st parameter
        20, //items per page
        \Illuminate\Pagination\Paginator::resolveCurrentPage(), //resolve the path
        ['path' => \Illuminate\Pagination\Paginator::resolveCurrentPath()]

    return $paginator->render();

Works great for me so far.

shez1983 replied 2 years ago

yeah except he asked for it 8 months ago..

Rajiv replied 2 weeks ago

Its very easy to add pagination in laravel

  1. Paginating Database Results
$users = DB::table('users')->paginate(15);
  1. View file
<table class="table table-bordered">
            <th width="300px;">Action</th>
        @if(!empty($users) && $users->count())
		    @foreach($users $key => $user)
		            <td>{{ $user->name }}</td>
		                <button class="btn btn-danger">Delete</button>
		       <td colspan="10">There are no data.</td>
{{ $user->render() }}

For more follow this post.

How To Add Pagination In Laravel

Pardeeptech replied 1 week ago
 $data = static::get();

    $result = [];
        foreach ($data as $key => $value) {
            $result[$value->type.'-'.$value->postid][] = $value;

    $paginate = 10;
    $page = Input::get('page', 1);

    $offSet = ($page * $paginate) - $paginate;  
    $itemsForCurrentPage = array_slice($result, $offSet, $paginate, true);  
    $result = new \Illuminate\Pagination\LengthAwarePaginator($itemsForCurrentPage, count($result), $paginate, $page);
    $result = $result->toArray();
    return $result;

Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us