id", $code, now()->addMinutes(10)); Session::put('user_id', $user->id); return $code; } /** * @throws \Exception */ public function verify(string $otp): bool { $user = User::find(Session::get('user_id')); if (! $user) { throw new UserNotFoundException('User not found'); } $code = Cache::get("otp_$user->id"); if ($code === $otp) { Cache::forget("otp_$user->id"); return true; } return false; } }