public function handle($command) { $token = EmailToken::find($command->token)->first(); if (!$token) { throw new InvalidConfirmationTokenException(); } $user = $token->user; $user->changeEmail($token->email); if (!$user->is_activated) { $user->activate(); } event(new UserWillBeSaved($user, $command)); $user->save(); $this->dispatchEventsFor($user); $token->delete(); return $user; }
protected function generateToken($user, $email) { $token = EmailToken::generate($user->id, $email); $token->save(); return $token; }