post('https://www.google.com/recaptcha/api/siteverify', [ 'secret' => $secret, 'response' => $token, 'remoteip' => $remoteIp ?? request()->ip(), ]); $result = $response->json(); return isset($result['success']) && $result['success'] === true; } catch (\Throwable $throwable) { Log::error('reCAPTCHA verification failed: '.$throwable->getMessage()); return false; } } /** * Render the Google reCAPTCHA widget. * * @param array $attributes */ public static function display(array $attributes = []): string { $sitekey = config('captcha.recaptcha.sitekey', config('captcha.sitekey')); if ($sitekey === null || $sitekey === '') { return ''; } $defaultAttributes = [ 'class' => 'g-recaptcha', 'data-sitekey' => $sitekey, ]; $attributes = array_merge($defaultAttributes, $attributes); $attributesString = ''; foreach ($attributes as $key => $value) { $attributesString .= sprintf('%s="%s" ', $key, htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8')); } return sprintf('
', trim($attributesString)); } /** * Render the Google reCAPTCHA JavaScript include. */ public static function renderJs(): string { return ''; } }