otp verification from user and db table

22 views Asked by At

The OTP is not verified ?

public function loginWithOtp(Request $request)
    {
        #Validation Logic
        $verificationCode   = VerificationCode::where('reset_mailid', $request->reset_mailid)->where('otp', $request)->first();

        $now = Carbon::now();

        // dd($verificationCode);
        if (!$verificationCode) {
            return redirect()->back()->with('error', 'Your OTP is not correct');
        }elseif($verificationCode && $now->isAfter($verificationCode->expire_at)){
            return redirect()->with('error', 'Your OTP has been expired');
        }

        $user = VerificationCode::whereId($request->user_id)->first();

        if($user){
            // Expire The OTP
            $verificationCode->update([
                'expire_at' => Carbon::now()
            ]);

            return redirect('/home');
        }

        return redirect()->back()->with('error', 'Your Otp is not correct');
    }

Anybody solve this Error?

i am experting the otp is verified from db table and user otp

0

There are 0 answers