Simple Pagination Example in Laravel 7

In this tutorial, I will teach you how to create a simple pagination in Laravel 7

Generally, We know pagination is a basic requirement of every project. Laravel 7 Provides direct function of pagination which are we use in our tutorial.

So let’s start our tutorial

Step 1: Create a dummy record.

We have to create a dummy record to use in pagination.

php artisan tinker
factory(App\User::class, 100)->create();

Step 2: Create a Route

Route::get('users', 'UserController@index');

Step 3: Create Controller

Create a Controller in app/Http/Controllers/UserController.php


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;

class UserController extends Controller{
    public function index(){
        $users = User::paginate(10);
	return view('users',compact('users'));

Step 4: Create Blade File

Create a blade file in resources/views/users.blade.php

	<table class="table table-bordered">
	            @foreach($users as $user)
	                    <td>{{ $user->name }}</td>
	                        <button class="btn">Delete</button>
	                <td>There are no data.</td>
	{!! $users->links() !!}	

Now open your browser and put the URL.

Stay Safe! Stay Healthy!

About Dhaval Shah

My name is Dhaval Shah. I'm a Laravel developer. I live in India and I love to write tutorials and tips that can help other developers. I am a big fan of PHP, Java-script, JQuery, Laravel, WordPress, and Bootstrap.
Follow me on Github / Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!