In Laravel, you can use the paginate
method of the Illuminate\Database\Eloquent\Builder
class to create a pagination. The paginate
method returns a LengthAwarePaginator
instance, which you can use to display the pagination in your view.
Here’s an example of how you can create a pagination in Laravel:
1. In your controller, use the paginate
method to retrieve the paginated results:
$users = User::paginate(15);
The paginate
method accepts a single argument, which is the number of results to show per page.
2. In your view, use the links
method of the LengthAwarePaginator
instance to display the pagination links:
<div class="pagination">
{{ $users->links() }}
</div>
This will display the pagination links with the default Bootstrap styling. You can customize the appearance of the pagination by modifying the pagination
view partial located at resources/views/vendor/pagination/bootstrap-4.blade.php
.