xxxxxxxxxx
use Illuminate\Pagination\Paginator;
public function boot()
{
Paginator::useBootstrap();
xxxxxxxxxx
// Retrieve paginated data from the database using Laravel's built-in pagination
$users = User::paginate(10);
// Render the Bootstrap 5 styled pagination links
echo $users->links('pagination::bootstrap-5');
xxxxxxxxxx
Run
php artisan vendor:publish --tag=laravel-pagination
To show the pagination correctly
xxxxxxxxxx
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Laravel 8 Pagination Demo - codeanddeploy.com</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-5">
<table class="table table-striped">
<thead>
<tr>
<th scope="col" width="1%">#</th>
<th scope="col" width="15%">Name</th>
<th scope="col">Email</th>
<th scope="col" width="10%">Username</th>
</tr>
</thead>
<tbody>
@foreach($users as $user)
<tr>
<th scope="row">{{ $user->id }}</th>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td>{{ $user->username }}</td>
</tr>
@endforeach
</tbody>
</table>
<div class="d-flex">
{!! $users->links() !!}
</div>
</div>
</body>
</html>