Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

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:
http://laravel.io/forum/11-13-2014-laravel-5-pagination

Last updated 9 years ago.
0

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.

0

yeah except he asked for it 8 months ago..

0

Its very easy to add pagination in laravel

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

For more follow this post.

How To Add Pagination In Laravel

0
 $data = static::get();
    

    $result = [];
    if(!empty($data)){
        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;
0

You need to create an instance of either an Illuminate\Pagination\Paginator or Illuminate\Pagination\LengthAwarePaginator.

Hope this article helpful to you for creating a Paginator manually: http://laravel.com/docs/master/pagination

I think it'll look something like this:

Use Illuminate\Pagination\Paginator

class Xyz {
    public function index()
    {
        // Build array
        $array = [];
        return new Paginator($array, $perPage);;
    }
}
Last updated 5 years ago.
0
$data = static::get();
    

    $result = [];
    if(!empty($data)){
        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;

2nd method Create pagination by using Vue with Laravel

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

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

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.