Pagination Example In Laravel

Websolutionstuff | Sep-24-2020 | Categories : Laravel

In this article, we will see a pagination example in laravel, as we all know pagination is a very common feature in all websites, if we want to display a specific number of details or images then we can use pagination. Laravel provides paginate method and it will automatically take care of setting the proper limit and offset based on the current page being viewed by the user. Here we will show you how to use pagination in laravel 6 and laravel 7. Also, we have to try to paginate method in laravel 6 and laravel 7.

So, let's see laravel custom pagination, laravel pagination links, and pagination in laravel 6/7/8.

First of all, we will create a controller and add the below code in the index() function, and we will use paginate() function for pagination.



namespace App\Http\Controllers;

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

class UserController extends Controller
    public function index(Request $request)
        $users = User::paginate(5);
        return view('users.index',compact('users'));



Now, we need to create a blade file for viewing. here we will add the links() function. So, it will generate pagination automatically.


    <div class="row">
        <div class="col-lg-12" style="margin-top: 15px ">
            <div class="text-center">
                <h2>Pagination Example in Laravel -</h2>
    <table class="table table-bordered">
        @foreach ($users as $user)
            <td>{{ $user->name }}</td>
            <td>{{ $user->email }}</td>
              <td colspan="4">No data found</td>  
    <div class="text-center">
        {!! $users->links() !!}





You might also like:

Recommended Post
Featured Post
Laravel 9 Yajra Datatable Example
Laravel 9 Yajra Datatable Exam...

In this artical we will see laravel 9 yajra datatable example. As we all used datatable on our backend side project, Her...

Read More


How To Integrate Razorpay Payment Gateway In Laravel 9
How To Integrate Razorpay Paym...

In this article, we see how to integrate razorpay payment gateway in laravel 9. As you all know if you are developi...

Read More


How To Roll back Specific Migration In Laravel
How To Roll back Specific Migr...

In this article, we will explore the process of rolling back specific migrations in Laravel, focusing on Laravel version...

Read More


How To Create Zip File Using Ziparchive in Laravel
How To Create Zip File Using Z...

In this article, we will see how to create a zip file using zipArchive in laravel. Sometimes we have requirements to hav...

Read More