Im using cursor to iterate through 100's of thousands of records... I want to make sure there is a next record. how can i determine if there is a next user?
User::cursor()->each(function ($user, $key) {
// how can i check if there is a next user?
if(next pointer of cursor exists){
$user->update([...]);
}
});
@davidifranco There’s no need to “check” if there is another record because the loop is only executed if there is another record. This is the entire point of generators, which is what cursors use under the hood:
foreach (User::query()->cursor() as $user) {
$user->update([
// ...
]);
}