PASSWORD RESET

Your destination for complete Tech news

How to create pagination in Laravel?

276 0
< 1 min read

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.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.