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();

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度