How to create Pagination in Laravel

Today now in this tutorial you can learn about how to add simple pagination in our blade file. If we are a beginners then i hope it will help you. Laravel provide us it’s own method for the pagination. But if we are work on code PHP then we need to write the long code for the pagination and render view etc but now in Laravel it is very simple.

So let’s select the data by using the following way in Controller.

Controller File:
public function getUser()
	$data = User::paginate(10);
	return view('users.index',compact('data'));

For the above example we can see now it will return us the pagination also with 10 records if we want to 5 or 15 etc then we can the change argument.

Now we have to render the pagination view so, let’s start and see.

Blade File:


<table class="table table-bordered">
            <th width="300px;">Action</th>
        @if(!empty($data) && $data->count())
		    @foreach($data as $key => $value)
		            <td>{{ $value->name }}</td>
		                <button class="btn btn-danger">Delete</button>
		        <td colspan="10">There are no data.</td>

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


Read Also : How to convert Object into Array in PHP?

Thanks for read. I hope it help you. For more you can follow us on facebook.


About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →