Here is the documentation for pagination: https://laravel.com/docs/8.x/pagination
Basically, you'd use Model::paginate(10) to paginate the items, there are default buttons you can use in the documentation to navigate between pages.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi!
I have 100 records in the database. I want to show per page 10 if the user click on the show more then I will give him 10 more records with the existing 10 records with limit & offset
plz give me a solution so or link wherefrom I could solve my problem
Here is the documentation for pagination: https://laravel.com/docs/8.x/pagination
Basically, you'd use Model::paginate(10) to paginate the items, there are default buttons you can use in the documentation to navigate between pages.
@jtemple042996 Thanks brother for replying...
======
I want not to use model pagination I want to use custom pagination in laravel because I have 1000 records in the database I want to show only 10 records limit if user click for more show then I want show more 10 records then will show 20
Checkout Laravel DataTables.
See Demo Application
I believe the OP is wanting to implement Infinite Scrolling @chaudigv? Horrible UX in my opinion; sometimes the user does not want to load more...
@chaudigv Brother, I want to make custom pagination and send in JSON response so that user will have only 10 records if click show more with model id then I send more 10 from the database
@tykus Yes Bro.. You are right i want to like this pagination.. Can you give me a solution or snippet so that solves my problem
If you are using jQuery @spiral, then have a look at jscroll plugin, which this tutorial demonstrates
@tykus bro.. I'm making this on the API side and want to send it to the react developer from the backend if he will click the show more then I will give more than 10 from the database
What is React giving the backend; it would seem the minimum you would get is a page query parameter?
React developer want 10 records from me on the first time whereas I have 100 of records in the database but want to send 10 records first time after if he clicks show more 10 records then I will give 10 records with existing 10 from the database.
we did not want to send more data from the backend when the frontend did not want to if he wants then will send 10 more whatever
Brother, maybe now you can find my logic that I want
From the backend you need to send to the fronted 10 records and information about hasMorePages() and nextPageUrl() that's it.
Then fronted developer can't have a problem to get it works.
Docs: https://laravel.com/docs/8.x/pagination#paginator-instance-methods
Yes, @michaloravec dear.. You are right if the developer want to get more 10 records for clicking the show more then I will give him more 10 with offset 10 records
Can you give me an example or link where I will get the concept and put the query in project
The React application literally needs only to send a page query parameter on the request to your backend; this will automatically be handled by the Builder's paginator. All you need is to paginate the query:
$results = Model::where(/* constraints */)->orderBy(/* sort direction */)
->paginate(10);
return response()->json($results);
The JSON structure of the Paginator instance will contain all of the necessary data, and the meta information described above:
{
"total": 50,
"per_page": 10,
"current_page": 1,
"last_page": 4,
"first_page_url": "http://laravel.app?page=1",
"last_page_url": "http://laravel.app?page=5",
"next_page_url": "http://laravel.app?page=2",
"prev_page_url": null,
"path": "http://your-domain.app",
"from": 1,
"to": 10,
"data":[
{
// Record...
},
{
// Record...
}
]
}
Once the React developer understands this structure they can extract the data to be rendered, and interrogate the meta data to understand if there are more records, or not.
Please or to participate in this conversation.