Hi,
I am trying to use increment()
to update the global tally of entrants to a competition, and also assign entry numbers to each one. I have the following in a user.update:after
hook:
kirby()->site()->increment('successfulEntrants');
$entryNumber = kirby()->site()->successfulEntrants()->toInt();
$newUser->update([
'entryNumber' => $entryNumber
]);
So when an editor updates the user, the successfulEntrants
total is increased by one, and the user is given a corresponding entryNumber
. The total is working as expected, but the entryNumber
is always one behind, like it is using the total before it has had the increment applied. So for example, when approving the first entry the successfulEntrants
changes to 1 (which is correct), but the user is given an entryNumber
of 0
Can anyone see where I am going wrong here?