App\Http\Controllers\User\UserController::deleteMail PHP Метод

deleteMail() публичный Метод

delete email
public deleteMail ( Illuminate\Http\Request $request ) : Xpressengine\Presenter\RendererInterface
$request Illuminate\Http\Request
Результат Xpressengine\Presenter\RendererInterface
    public function deleteMail(Request $request)
    {
        $address = $request->get('address');
        // 해당회원이 가진 이메일을 찾는다.
        $selected = null;
        $pendingEmail = $this->user->getPendingEmail();
        if ($pendingEmail !== null && $pendingEmail->getAddress() === $address) {
            $selected = $pendingEmail;
        } else {
            foreach ($this->user->emails as $mail) {
                if ($mail->address === $address) {
                    $selected = $mail;
                    break;
                }
            }
        }
        // 해당회원이 가진 이메일이 아닐 경우 예외처리한다.
        if ($selected === null) {
            $e = new InvalidArgumentException();
            $e->setMessage('존재하지 않는 이메일입니다.');
            throw $e;
        }
        XeDB::beginTransaction();
        try {
            $this->handler->deleteEmail($selected);
        } catch (\Exception $e) {
            XeDB::rollback();
            throw $e;
        }
        XeDB::commit();
        return XePresenter::makeApi(['message' => '삭제되었습니다.']);
    }