Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mr.sarkaw's avatar

OTP with laravel api and firebase

how to use otp firebase with laravel api (backend only not through frontend)? for example i have a mobile app and users register to app, how to use firebase otp with the api laravel? is there anyone do this process before?

0 likes
3 replies
Lara_Love's avatar

your mean this

public function generate($mobile)
    {
        $user = User::where('mobile', $mobile)->first();

        # User Does not Have Any Existing OTP
        $verificationCode = VerificationCode::where('user_id', $user->id)->latest()->first();

        $now = Carbon::now();

        if($verificationCode && $now->isBefore($verificationCode->expire_at)){
            return $verificationCode;
        }

        // Create a New OTP
        return VerificationCode::create([
            'user_id' => $user->id,
            'otp' => rand(123456, 999999),
            'expire_at' => Carbon::now()->addMinutes(10)
        ]);
    }

Please or to participate in this conversation.