dimanche 9 septembre 2018

Laravel: Do one query update and then, if that succeeds, do the next, otherwise, do neither

So, I want to update two different user accounts with the same value.

Scenario: User 1 transfers money to User 2:

$transfer_from = $account->decrement('balance', $amount);

$transfer_to = Account::where('user_wallet_address', $receiver_wallet_address)->increment('balance', $amount);

But, what I want, is something like this:

$account->decrement('balance', $amount)->$transfer_to;

As in if the decrement succeeds, then update the other user's balance, otherwise, both should fail

Thoughts?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire