Hello Artisan,
In this tutorial, I will show you how we can customize our default Laravel 9 pagination. How to customize default pagination in laravel 9 is today's tutorial. You know that Laravel provides default pagination.
Now if you want to customize it, then what you will do? Laravel also provides a custom pagination template that can be used to easily customizable that Laravel 9 pagination. So if you don't know how to customize Laravel 9 pagination, then this Laravel 9 custom pagination example tutorial is for you.
By default, Laravel provides very simple pagination. But in this tutorial, I will create our own custom pagination. But if you are not using bootstrap pagination and you want to customize then you can easily change OR if you want to add a new bootstrap pagination layout then we can follow this laravel 9 custom pagination tutorial.
Preview:
Step 1: Create Pagination Template
As we are going to use laravel custom pagination template, that's why run the below command to have it.
php artisan vendor:publish --tag=laravel-pagination
After running the above command run you will get a new folder "pagination" on views files(resources/views/vendor). In the pagination folder you will get the following files by default:
But we are going to use our own custom pagination template. We don't use any of the above templates.
Step 2: Add Route
Now we need routes to see our pagination page. So create this below the route and create some dummy data of users.
routes/web.php
Route::get('/', 'TestController@index');
Read also : Laravel 9 Ajax Pagination with Next And Previous Button
Step 3: Add Controller
Ok, now we have to add a new controller method "index()" in your TestController, so if you haven't created TestController then you can create it and paste the following code.
app/Http/Controllers/TestController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class TestController extends Controller
{
public function index()
{
$users = \App\User::paginate(7);
return view('welcome',compact('users'));
}
}
Step 4: Create Blade File
Now we need to create our blade file for users' view and custom pagination template. To create it with the following path.
resources/views/vendor/pagination/custom.blade.php
Read also : Laravel 9 Infinite Scroll (Load More) Example Tutorial
At last, we have to create a welcome.blade.php
file and we will use our custom pagination template. So let's create the welcome page and put below code on it.
resources/views/welcome.blade.php
Read also : Create Custom Pagination with Pretty URL in Laravel
Hope this laravel 9 custom pagination tutorial will help you.
#laravel #laravel-9x