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
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.
Its very easy to add pagination in laravel
$users = DB::table('users')->paginate(15);
@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.
$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;
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);;
}
}
$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
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community