Raviya Technical
Published in

Raviya Technical

Laravel Advance | Next Previous Link Button Pagination

Do you want to add the next previous button on pagination in laravel 6? if yes then I will help you to create simple pagination with laravel 6. we will customize the pagination link with only the next and previous buttons in laravel 6.

we can add the next and the previous link on pagination using simplePaginate() in laravel 6, laravel 7, and laravel 8 applications. laravel provides a new eloquent method simplePaginate() for adding simple pagination with only the next previous button link.

If you also want to add pagination with next and previous link then follow below some steps and make it done as like below screenshot

Create Route:

In the first step, we will create simple routes for getting users and viewing them, so let’s add a new route in the web.php file:


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

Create Controller:

Now, we will create a new UserController with the index() method. in the index() we will write simple pagination code. so let’s create as like bellow


<?phpnamespace App\Http\Controllers;use Illuminate\Http\Request;
use App\User;
class UserController extends Controller{public function index(){$users = User::simplePaginate(5);return view('users', compact('users'));}}

Create View File:

In this last step, we will create a simple blade file and display users with pagination. so let’s add bellow code:


<!DOCTYPE html><html><head><title>Laravel Next Previous Link Button Pagination - raviyatechnical</title><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"></head><body><div class="container"><h1>Laravel Next Previous Link Button Pagination - raviyatechnical</h1><table class="table table-bordered"><tr><th>ID</th><th>Name</th></tr>@foreach($users as $user)<tr><td>{{ $user->id }}</td><td>{{ $user->name }}</td></tr>@endforeach</table>{{ $users->links() }}</div></body></html>

Ok, now you have to create some dummy records on users table.

Then you can check it.

I hope it can help you…




PHP, Laravel And Flutter Development

Recommended from Medium

What does your perfect in-store infrastructure look like?

Java web app containerization and migration to Azure Kubernetes Service

5 Advanced Operations to Handle Numbers in Python

String_agg and String_to_array functions in PostgreSQL

Github Actions and Azure

Adobe Acrobat for Teams: Making Collaboration Effortless

Writing a custom Flutter widget

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Raviya Technical

Raviya Technical


More from Medium

Laravel Advance | Laravel US State Seeder Example

Laravel 8 Toastr Notifications Example

Mastering Sluggable Package in Laravel

What’s new in Laravel 8