Pagination Controller:
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\user; class Pagination extends Controller { public function paginate(){ // $users = User::all(); $users = User::paginate(8); return view('pagination',compact('users')); } }
Routing: routes > web.php
Route::get('list','Pagination@paginate');
pagination.blade.php
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Pagination</title> <link rel="stylesheet" href="/css/bootstrap.css" crossorigin="anonymous"> </head> <body> <div class="container"> <div class="row"> <div class="col-lg-6 offset-lg-3"> <center><h2>Laravel Pagination</h2></center> <table class="table table-hover"> <thead> <tr> <th scope="col">No</th> <th scope="col">Name</th> <th scope="col">Email</th> </tr> </thead> <tbody> @foreach ($users as $user) <tr> <td>{{$loop->index+1}}</td> <td>{{$user->name}}</td> <td>{{$user->email}}</td> </tr> @endforeach </tbody> </table> <div> {{$users->links()}} </div> </div> </div> </div> </body> </html>
Customizing The Pagination View
However, the easiest way to customize the pagination views is by exporting them to your resources/views/vendor directory using the vendor:publish command:
php artisan vendor:publish --tag=laravel-pagination
This command will place the views in the resources/views/vendor/pagination directory. The default.blade.php file within this directory corresponds to the default pagination view. Edit this file to modify the pagination HTML.
Using default bootstrap
{{$users->links("pagination::bootstrap-4")}}