Laravel 5.5 Ajax Pagination Example

November 13, 2017 | Category : Laravel 5.5 Laravel 5 Ajax Bootstrap Laravel PHP

Hi Guys.

In this article i will let you know how to make jquery ajax pagination in Laravel 5.5 application.

As we know, today ajax is more use because every one wants to his web app should be work fast. So if you want make your web app more fast then you have to use jquery ajax. Using jquery ajax you can simply get data and post data using api. So here i want to share with you how to create ajax paginate in laravel 5.5 application.

You have to simple follow bellow few step and get layout like as bellow:


Step 1: Create Table and Model

First thing is we have to create "tagslist". so we have to create migration for tagslist table using Laravel 5.5 php artisan command, so first fire bellow command:

php artisan make:migration create_tagslist_table

After this command you will find one file in following path database/migrations and you have to put bellow code in your migration file for create articles table.


use Illuminate\Support\Facades\Schema;

use Illuminate\Database\Schema\Blueprint;

use Illuminate\Database\Migrations\Migration;

class CreateTagslistTable extends Migration



* Run the migrations.


* @return void


public function up()


Schema::create('tagslist', function (Blueprint $table) {







* Reverse the migrations.


* @return void


public function down()





Next run migration for creating table by following command:

php artisan migrate

Next we will create model for "tagslist" table so just run bellow command and create new model:

php artisan make:model TagList

Ok, so after run bellow command you will find app/TagList.php and put bellow content in TagList.php file:



namespace App;

use Illuminate\Database\Eloquent\Model;

class TagList extends Model


public $table = "tagslist";

public $fillable = ['name'];


Step 2: Add Route

In second step, we will add new route in web.php file. One route for generate form and also get records in json format when fire ajax:



Step 3: Create Controller Method

In third step, we have to create ajaxPagination() in your controller, as per example i will create method in my HomeController.



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\TagList;

class HomeController extends Controller


public function ajaxPagination(Request $request)


$tags = TagList::paginate(5);

if ($request->ajax()) {

return view('presult', compact('tags'));


return view('taglist',compact('tags'));



Step 4: Create Blade Files

Next, we will create two view file as like following.




<!DOCTYPE html>



<title>Laravel 5.5 AJAX Pagination Example</title>

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

<script src="//"></script>



<div class="container">

<h1>Laravel 5.5 AJAX Pagination Example</h1>

<div id="tag_container">




<script type="text/javascript">

$(window).on('hashchange', function() {

if (window.location.hash) {

var page = window.location.hash.replace('#', '');

if (page == Number.NaN || page <= 0) {

return false;








$(document).on('click', '.pagination a',function(event)





var myurl = $(this).attr('href');

var page=$(this).attr('href').split('page=')[1];




function getData(page){



url: '?page=' + page,

type: "get",

datatype: "html"





location.hash = page;


.fail(function(jqXHR, ajaxOptions, thrownError)


alert('No response from server');







<table class="table table-bordered">



<th width="100px">ID</th>





@foreach ($tags as $tag)


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

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





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

Now you can run this example and see enjoy.

I hope you found your best solution.