Laravel 5.5 pagination example from scratch

September 1, 2017 | Category : Laravel 5.5 Laravel 5 Bootstrap Laravel PHP

Are you wanted to create pagination in your laravel 5.5 application ?, If Yes then you are a right place. Pagination in always require when we have to display table records. If you have thousands of records in table but you can't display at a time all the records so it's must be display per page some records. So here pagination will help to display per page something records.

If you are using core php then you have trouble to implement logic for pagination, but in laravel 5.5 version they provide very simple way to make pagination for your application. Here i will let you know very basic and simple example of pagination.

So, let' just follow three things to do pagination example:

Add Route:

First things is create route for simple pagination example, So let's open your web.php file and put bellow route:


Route::get('mypagination', 'HomeController@myPagination');

Add Controller Method:

Now, we have to add myPagination() method in HomeController, in this method we write database query builder condition. So let's just add bellow method on home controller.



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User;

class HomeController extends Controller



* Create a new controller instance.


* @return void


public function myPagination()


$users = User::paginate(5);

return view('myPagination',compact('users'));



Add View File:

At last we will create blade file and display pagination layout using links() method, so you have to create blade file and put bellow code:


<!DOCTYPE html>



<title>Laravel 5.5 Pagination Example</title>

<link href="//" rel="stylesheet">



<div class="container">

<h2>Laravel 5.5 Pagination Example</h2>

<table class="table table-bordered">






@if($users->count() > 0)

@foreach($users as $user)


<td>{{ $user->id }}</td>

<td>{{ $user->name }}</td>

<td>{{ $user->email }}</td>





{{ $users->links() }}




Now you can run this simple example.

I hope you found your best...