Hee! Well yeah, that's true because whenever you go to the next page you refresh the page and $i is 1 again. So instead you need to set $i based on the current page of the pagination. You can for example do something like this in your controller
public function index()
{
$perPage = 20;
$users = User::whereNotIn('role_id', [1, 2])
->where('total_points', '!=', 0)
->orderBy('total_points', 'desc')
->paginate($perPage);
$counter = 1;
if (!$users->onFirstPage()) {
// Get the current page (2)
// Then calculate the current counter
// currentpage - 1 * number of items + 1
// For example if on the second page, counter starts with 21
// (2 - 1) * 20 + 1 = 21 // 2
// (4 - 1) * 20 + 1 = 61 // page 4
$counter = ($users->currentPage() - 1) * $users->perPage() + 1;
}
return view('users.index', [
'users' => $users,
'counter' => $counter,
]);
}
In your view you can then use $counter instead of $i.
Let me know if that works for you ;)
Documentation: https://laravel.com/docs/5.7/pagination#paginator-instance-methods