Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
laravel
pagination
communitycreator

How to perform Pagination on Eloquent results in Laravel

Chinweuba Elijah Azubuike

What is Pagination in Laravel?

Pagination makes it easy for your user to navigate between pages in your application.

Pagination limits the amount of content that is fetched and displayed from your database. For instance, if you have 100 users in your database and you only want to see 15 on a single page, Pagination helps you achieve this easily.

widget

Example

In this example, we use the paginate() method as follows:

$users = App\User::paginate(15);

The code above receives the results from the Eloquent query and fetches them in batches of 15 rows.

$post = App\Post::paginate(30);

The code above receives the results from the Eloquent query and fetches them in batches of 30 rows. Basically, the paginate method fetches the Eloquent query results in batches, and supply links to any remaining results if necessary.

Summary


The paginate() method limits or places constraints (as defined in the argument passed into the paginate() method) on the Eloquent query result based on the current page being viewed. The value of the page query string from the HTTP request is used to detect the current page, which is automatically detected by Laravel, and inserted into the links generated by the Paginator.

RELATED TAGS

php
laravel
pagination
communitycreator

CONTRIBUTOR

Chinweuba Elijah Azubuike
RELATED COURSES

View all Courses

Keep Exploring