Are they loaded over ajax? You could store the current 10 IDs and have the next call exclude any posts in that array.
Problem with pagination in combination with adding new records
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.
I forgot to tell you.
I have implemented your solution with minor modification.
I have stored all IDs and pass them as array in post request to exclude them, but i have also store the max ID and have something like this in my query
$query->where('id', '<', $maxId)
With this max ID i have excluded all new posts added after i load my page (new posts will be loaded only after page refresh).
Please or to participate in this conversation.