Last active
December 13, 2024 11:26
-
-
Save alsma/4d71b7252832b7c93e2eafc656ba6669 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class EmailManager | |
{ | |
public function confirmEmail(User $user): User | |
{ | |
$user = \DB::transaction(function () use ($user) { | |
$user = User::lockForUpdate()->findOrFail($user->id); | |
$user->email_confirmed = true; | |
$user->save(); | |
event(new UserErmailConfiming($user)); // DO some operations inside transactions (i.e. log user actions to DB) | |
return $user; | |
}); | |
event(new UserErmailConfimed($user)); // DO some operations in third party services (i.e. create mailchimp contact) | |
return $user; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment