douren7179 2017-12-31 17:40
浏览 104

无法删除模型,如果应用程序返回错误

I have some weird issue. I don't know if I'm doing anything wrong.

Task

Simple email verification task. As below:

  1. User submit request to get new email verification link to his inbox.
  2. User click on the link was sent to his inbox which lead to verification page
  3. The application verify email and verification token passed in URL
  4. If email and token verified. Application will mark user as verified user and delete existing verification code recored/model from email verifications table.

Everything is working fine until deleting the existing record. Each time I try to delete the existing record the application returns 422 Unprocessable entity error.

Code

Controller

public function verifyEmail(EmailVerifications $emailVerificationsRepo,
    Request $request){
    $this->emailVerificationValidator($request);
    $status = $emailVerificationsRepo->verify(
    $request->get('email'),
    $request->get('token')
    );
    if($status){
        return $this->successResponse();
    }
    return $this->errorResponse();
  }

Repository

/**
   * Verify activation code
   * @param  string $email
   * @param  string $token
   * @return boolean
   */
  public function verify($email, $token){
    $verification = $this->findWhere([
      'email' => $email,
    ])->first();
    if(!$verification){
      return false;
    }
    if(app('hash')->check($token, $verification->verification_code)){
      $user = $verification->user;
      \DB::table('email_verifications')->where('email', $email)->delete();
      $user->verifyEmail();
      return true;
    }
    return false;
  }

/**
* Delete all verification records for giving email
* @param  string $email
* @return boolean
*/
protected function deleteExisting($email){
  return $this->deleteWhere([
    'email' => $email,
  ]);
}

Environment:

MacOs, Nginx, Lumen 5.5

Any help? thanks in advance

  • 写回答

1条回答 默认 最新

  • dqf2015 2017-12-31 19:00
    关注

    try this: \DB::table('email_verifications')->where('email', $email)->first()->delete();

    评论

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码