backend2-plus/google-captcha-bundle
Simple Symfony bundle for Google reCAPTCHA integration.
composer require sasa1007/google-captcha-bundle
Note: After installation, you need to manually configure the bundle as described below.
Create configuration file config/packages/google_captcha.yaml:
google_captcha:
secret: '%env(GOOGLE_CAPTCHA_SECRET)%'
Add to your .env file:
GOOGLE_CAPTCHA_SECRET=your_google_recaptcha_secret_key
Note: Replace your_google_recaptcha_secret_key with your actual Google reCAPTCHA secret key from Google reCAPTCHA Admin Console.
use BeckUp\GoogleCaptchaBundle\Service\GoogleCaptchaService;
class YourController extends AbstractController
{
public function someAction(Request $request, GoogleCaptchaService $captchaService)
{
$result = $captchaService->verify($request);
if ($result->success) {
// reCAPTCHA passed
} else {
// reCAPTCHA failed
}
}
}
Add Google reCAPTCHA script to your template:
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<div class="g-recaptcha" data-sitekey="your_site_key"></div>
To remove the bundle:
rm config/packages/google_captcha.yaml
composer remove sasa1007/google-captcha-bundle
Note: The bundle is automatically unregistered and service definitions are removed when you uninstall the package.
How can I help you explore Laravel packages today?