Xpressengine\User\UserHandler::createEmail PHP Method

createEmail() public method

새로운 이메일을 생성한다
public createEmail ( Xpressengine\User\UserInterface $user, array $data, boolean $confirmed = true ) : Xpressengine\User\EmailInterface
$user Xpressengine\User\UserInterface user
$data array data
$confirmed boolean confirmed
return Xpressengine\User\EmailInterface
    public function createEmail(UserInterface $user, array $data, $confirmed = true)
    {
        if ($confirmed === true) {
            $email = $this->emails()->create($user, $data);
        } else {
            $email = $this->pendingEmails()->create($user, $data);
        }
        return $email;
    }

Usage Example

 /**
  * add email
  *
  * @param Request $request
  *
  * @return \Xpressengine\Presenter\RendererInterface
  * @throws Exception
  */
 public function addMail(Request $request)
 {
     $input = $request->only('address');
     // validation
     $this->validate($request, ['address' => 'email|required'], [], ['address' => xe_trans('xe::email')]);
     // 이미 인증 요청중인 이메일이 있는지 확인한다.
     $useEmailConfirm = $this->handler->usingEmailConfirm();
     if ($useEmailConfirm) {
         if ($this->user->getPendingEmail() !== null) {
             $e = new PendingEmailAlreadyExistsException();
             throw new HttpException(400, $e->getMessage(), $e);
         }
     }
     // 이미 존재하는 이메일이 있는지 확인한다.
     if ($this->emails->findByAddress($input['address'])) {
         $e = new MailAlreadyExistsException();
         throw new HttpException(400, $e->getMessage(), $e);
     }
     //array_set($input, 'userId', $this->user->getId());
     XeDB::beginTransaction();
     try {
         $mail = $this->handler->createEmail($this->user, $input, !$useEmailConfirm);
         if ($useEmailConfirm) {
             /** @var EmailBroker $broker */
             $broker = app('xe.auth.email');
             $broker->sendEmailForConfirmation($mail);
         }
     } catch (\Exception $e) {
         XeDB::rollback();
         throw $e;
     }
     XeDB::commit();
     \Session::flash('alert', ['type' => 'success', 'message' => '추가되었습니다.']);
     return XePresenter::makeApi(['message' => '추가되었습니다']);
 }
All Usage Examples Of Xpressengine\User\UserHandler::createEmail