Paginate Does Not Account For Changing Results
I use paginate in Laravel to load a large amount of data. Data that changes quickly. The problem is that as the user scrolls through the data, new rows are being inserted at the top. This creates an issue where the user sees a duplicate row that got pushed out of page 1 into page 2 in the time between the user loading page 1 and page 2. For example:
User A loads results using ->simplePaginate(2).
Page #1 loads:
inserts a row into the database.
User A now scrolls past his results on page #1 and page #2 loads:
User A now just saw:
- E <-- error
Is there a way I can easily account for this when loading the second page?
User A should have seen
It would also be super cool to pass along some information when User A loads page #2 saying "Hey, there are new results at the top now."
Take a timestamp on page 1, and then add an additional clause to the query, asserting that
created_at is before the timestamp.
$beforeTime = $request->input('before_time', Carbon::now()); $items = Item::where('created_at', '<=', $beforeTime)->paginate(2);
Lastly, make sure to append the
before_time parameter to the pagination links:
echo $items->appends(['before_time' => $beforeTime])->links();
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms