Problem with pagination in combination with adding new records

Posted 1 month ago by milosradic

Hi all,

I have a problem with my pagination. I have posts that are paginated (10 per page - i have load more button on page and it loads next 10 posts on same page etc.) and users on website can add new posts.

The problem is when User1 load first 10 posts and User2 creates for example 3 posts, then, when User1 loads next 10 posts, first 3 posts in second 10 posts are already loaded in first 10 posts (so i get duplicates in list). Does someone know any workaround for this? (I can try to apply solution either in Laravel or on frontend with javascript and load more button)

I had an idea to pass ID of first post and to query only posts that have ID less than this ID, but my posts are not sorted by ID and that will not work. Actually, my posts can be sorted by created_at (most relevant), by distance (i have lat and long for posts and take users current location to calculate the distance) and by most participants (users can participate to posts). That is a problem because i have to pass different start post ID or some_value so i can query only posts that comes after that one at beginning of post list.

Sorry for bad english and maybe bad explanation but you will figure out what is my problem.

Any suggestions are welcome.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.