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

问题描述 投票:1回答:1

我有一些奇怪的问题。我不知道我做错了什么。

任务

简单的邮件验证任务。如下:

  1. 用户提交请求以获取其收件箱中的新电子邮件验证链接。
  2. 用户点击链接已发送到他的收件箱,导致验证页面
  3. 应用程序验证在URL中传递的电子邮件和验证令牌
  4. 如果验证了电子邮件和令牌应用程序将用户标记为已验证用户,并从电子邮件验证表中删除已记录的现有验证码/型号。

在删除现有记录之前,一切正常。每次我尝试删除现有记录时,应用程序返回422 Unprocessable entity error。

调节器

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

知识库

/**
   * 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,
  ]);
}

环境:

MacOs,Nginx,Lumen 5.5

有帮助吗?提前致谢

php laravel eloquent lumen
1个回答
-1
投票

试试这个:\ DB :: table('email_verifications') - > where('email',$ email) - > first() - > delete();

© www.soinside.com 2019 - 2024. All rights reserved.