Download the PHP package dutchcodingcompany/livewire-recaptcha without Composer
On this page you can find all versions of the php package dutchcodingcompany/livewire-recaptcha. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dutchcodingcompany/livewire-recaptcha
More information about dutchcodingcompany/livewire-recaptcha
Files in dutchcodingcompany/livewire-recaptcha
Package livewire-recaptcha
Short Description Add Google Recaptcha V3 support to your Laravel Livewire components
License MIT
Homepage https://github.com/dutchcodingcompany/livewire-recaptcha
Informations about the package livewire-recaptcha
Livewire ReCAPTCHA v3/v2/v2-invisible
This package provides a custom Livewire directive to protect your Livewire functions with a Google reCAPTCHA (v2 + v2 invisible + v3) check.
Installation
Configuration
Read https://developers.google.com/recaptcha/intro on how to create your own key pair for the specific ReCaptcha version you are going to implement.
This package supports the following versions. Note that each version requires a different sitekey/secretkey pair:
Version | Docs | Notes |
---|---|---|
v3 (recommended) | V3 Docs | |
v2 | V2 Docs | |
v2 invisible | V2 Docs | Use 'size' => 'invisible' |
Your options should reside in the config/services.php
file:
Component
In your Livewire component, at your form submission method, add the #[ValidatesRecaptcha]
attribute:
For fine-grained control, you can pass a custom secret key and minimum score (applies only to V3) using:
View
On the view side, you have to include the Blade directive @livewireRecaptcha
. This adds two scripts to the page,
one for the reCAPTCHA script and one for the custom Livewire directive to hook into the form submission.
Preferrably these scripts are only added to the page that has the Captcha-protected form (alternatively, you can add
the @livewireRecaptcha
directive on a higher level, lets say your layout).
Secondly, add the new directive wire:recaptcha
to the form element that you want to protect.
You can override any of the configuration values using:
Finishing up
The Google ReCAPTCHA validation will automatically occur before the actual form is submitted. Before the save()
method
is executed, a serverside request will be sent to Google to verify the Captcha challenge. Once the reCAPTCHA
response has been successful, your actual Livewire component method will be executed.
Error handling
When an error occurs with the Captcha validation, a ValidationException is thrown for the key gRecaptchaResponse
.
There is a translatable error message available under 'livewire-recaptcha::recaptcha.invalid_response'
.