Laravel 9 Pagination Example Tutorial
https://www.itsolutionstuff.com/post/laravel-9-pagination-example-tutorialexample.html
Last updated
https://www.itsolutionstuff.com/post/laravel-9-pagination-example-tutorialexample.html
Last updated
Hello Dev,
This tutorial will give you an example of laravel 9 pagination example blade. I explained simply about laravel 9 pagination bootstrap 5 example. This tutorial will give you a simple example of the laravel 9 pagination tailwind example. you will learn how to add pagination in laravel 9. So, let's follow a few steps to create an example of how to create pagination in laravel 9.
We know pagination is a primary requirement of each and every project. so if you are a beginner with laravel then you must know how to use pagination in laravel 9 and what is another function can use with laravel 9 pagination.
In this example, we will run the migration and create a "users" table. Then we will create dummy records using the tinker command. Then we will display that users with pagination. by default laravel pagination use Tailwind CSS design, we will use bootstrap 5 design for pagination here.
So, let's follow below tutorials:
Step 1: Install Laravel 9
This is optional; however, if you have not created the laravel app, then you may go ahead and execute the below command:
Step 2: Database Configuration
In second step, we will make database configuration for example database name, username, password etc for our crud application of laravel 9. So let's open .env file and fill all details like as bellow:
.env
Read Also: Laravel 9 Eloquent Mutators and Accessors Example
Step 3: Create Dummy Users
In this step, we need to run migration command to create users table and then create dummy users records so we can see pagination.
Let's run migration command:
Next, run ticker command to add dummy users:
Step 4: Add Route
First thing is we put one route in one for list users with pagination. So simple add both routes in your route file.
routes/web.php
Step 5: Create Controller
Same things as above for route, here we will add one new method for route. index() will return users with pagination data, so let's add bellow:
app/Http/Controllers/UserController.php
Step 6: Create Blade File
In this step, you need to create users blade file and put bellow code with links() so it will generate pagination automatically. So let's put it.
resources/views/users.blade.php
Run Laravel App:
All the required steps have been done, now you have to type the given below command and hit enter to run the Laravel app:
Now, Go to your web browser, type the given URL and view the app output:
Output:
If you need advance used of pagination then you can see bellow how to use.
Pagination with appends parameter
Pagination with appends request all parameters
Read Also: Laravel 9 Multi Auth: Create Multiple Authentication in Laravel
I hope it can help you....