Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

pagination in Laravel

How to use pagination in Laravel 8 ?

In this tutorial, I will give you a simple example of laravel pagination, So you can easily apply it with your laravel 5, laravel 6, laravel 7, and laravel 8 application, Sometimes we need to use paginate data in controller or Blade file in laravel application.

In core PHP we write more line code for pagination. But Laravel framework provides the best paginate method which is very simple and easy to use.

Laravel Pagination

Laravel paginator is integrated with the Query builder and Eloquent ORM and provides convenient, easy-to-use pagination of database records with zero configuration.

We all know pagination is a basic requirement of each and every laravel application, So lets start with a simple pagination example in laravel with scratch.

Generating Migration :

php artisan make:migration create_pagination_examples_table

Migration Structures :


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePaginationExamplesTable extends Migration
     * Run the migrations.
     * @return void
    public function up()
        Schema::create('pagination_examples', function (Blueprint $table) {

     * Reverse the migrations.
     * @return void
    public function down()

Run Migration :

php artisan:migrate
pagination in Laravel

Make Model :

php artisan make:model PaginationExample



  namespace App;

  use Illuminate\Database\Eloquent\Model;

  class PaginationExample extends Model
      protected $table = 'pagination_examples';

Generate Dummy Data using Faker and Tinker :

Now we insert some dummy records in our pagination_examples table, If you don’t know how faker and tinker work please read the given below article.

Recommended Article : Generate data using faker and tinker.

To enter the Tinker environment, run the tinker Artisan command,

php artisan tinker

>>> Factory('App\PaginationExample',40)->create()
pagination in Laravel
pagination in Laravel

Now we have Sufficient records to paginate our pagination_examples table data in the Controller or Blade file.




   public function ListPaginationData(){
      $paginateData = PaginationExample::paginate(10);
      return view('paginationexample',compact('paginateData'));

Blade File

<!DOCTYPE html>
<html lang="en">
      <title>Laravel Pagination Example</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="">
      <script src=""></script>
      <script src=""></script>
      <div class="container">
         <table class="table">
                  <th>Book Name</th>
                  <th>Book Author</th>
               @foreach($paginateData as $key => $data)
                  <td>{{ $key+1 }}</td>
          <div class="mt-5" style="float:right">
                  {{ $paginateData->links()}}

Finally, we paginated the App\PaginationExample model and indicate that we plan to display 10 records per page. As you can see below the given images.

How to use pagination in Laravel
How to use pagination in Laravel

Note : While you are using query Builder, Try this Method

$users = DB::table('pagination_examples')->simplePaginate(15);

In this article, we learned “How to use pagination in Laravel”, I hope this article will help you with your Laravel application Project.

Also Read : Encode and Decode in Laravel. | Simple Pagination in Laravel.