Skip to content

Instantly share code, notes, and snippets.

@alsma
Last active November 20, 2020 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alsma/4d71b7252832b7c93e2eafc656ba6669 to your computer and use it in GitHub Desktop.
Save alsma/4d71b7252832b7c93e2eafc656ba6669 to your computer and use it in GitHub Desktop.
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;
}
}
class SocialProfileManager
{
public function connectProfile(User $user, $socialNetworkUserData): User
{
$user = \DB::transaction(function () use ($user, $socialNetworkUserData) {
// do some logic here
// ....
if ($user->email === $socialNetworkUserData->email) {
$user = $this->emailManager->confirmEmail($user);
}
return $user;
});
return $user;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment