You'd need to use $user->fresh()->wallet in your 2nd function to retrieve the updated value from the database. Just using $user->wallet gets the cached value from the initial lookup, not the value that was updated by function 1.
@lolsokje
Is this idea of updating still viable? thinking that I have a list of numbers that can be called together and I need to block, but update the data after blocking.
@Snapey Hello, thanks for responding. My question about this is: I have a function where it reserves random numbers that it takes from a list that is saved within the "product" table and I have a cron where it updates this list every 1 minute, but it can happen from the reserveNumbers function and the cron run at the same time and this generates competition where one of them can take an outdated list and update the list. I tried using lockforupdate with transaction but it still continues, and I tried the refresh solution.
The increment function tells the database to add to the column. it cannot be interrupted so it is known as 'atomic'
Your approach is get the value, add to the value, save the value. Before saving, another process can get the old value as well. last to save wins. You can avoid this in this case with increment