Laravel 5 Pagination example

By Hardik Savani | April 21, 2016 | | 7461 Viewer | Category : Laravel


Share this post:

In this tutorial you can learn how to add simple pagination in your blade file. If you are beginners then it can help you. Laravel 5 provide its own method for pagination. But if you are work on code PHP then you have to write long code for pagination and render view etc but in Laravel it is very simple so let's select data following way in Controller.

Controller File:

public function getUser()

{

$data = User::paginate(10);

return view('users.index',compact('data'));

}

In above example you can see now it will return pagination with 10 records if you want to 5 or 15 etc then you can change argument. Now we have to render pagination view so, let's see.

Blade File:

@extends($theme)


@section('content')


<table class="table table-bordered">

<thead>

<tr>

<th>Name</th>

<th width="300px;">Action</th>

</tr>

</thead>

<tbody>

@if(!empty($data) && $data->count())

@foreach($data as $key => $value)

<tr>

<td>{{ $value->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>


{!! $data->render() !!}


@endsection



We are Recommending you: