if ($item->currentPage() < $items->lastPage()) {
//show load more button
}
This works fine, but if I forget() some rows, the pagination becomes incorrect. How can I recalculate the pagination so that its correct, after my routine above
You have to first filter out all the results you don't want using forget. After that, you need to paginate manually. You can't use the Laravel default query paginator since that is working based on the query and not the results you removed from it.
You can create your own pagination object like so
$users = Item::all();
$page = $request->input('page', 1); // Get the ?page=1 from the url
$perPage = 15; // Number of items per page
$offset = ($page * $perPage) - $perPage;
return new LengthAwarePaginator(
array_slice($users->toArray(), $offset, $perPage, true), // Only grab the items we need
count($users), // Total items
$perPage, // Items per page
$page, // Current page
);