I have some weird issue. I don't know if I'm doing anything wrong.
Simple email verification task. As below:
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.
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
try this: \DB::table('email_verifications')->where('email', $email)->first()->delete();