https://github.com/antonioribeiro/twill-google-recaptcha
A Twill Capsule to add and handle Google reCAPTCHA
https://github.com/antonioribeiro/twill-google-recaptcha
Last synced: 8 months ago
JSON representation
A Twill Capsule to add and handle Google reCAPTCHA
- Host: GitHub
- URL: https://github.com/antonioribeiro/twill-google-recaptcha
- Owner: antonioribeiro
- License: mit
- Created: 2022-11-16T13:40:00.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-30T13:50:49.000Z (over 1 year ago)
- Last Synced: 2025-01-06T01:43:50.203Z (9 months ago)
- Language: PHP
- Size: 55.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# Google reCAPTCHA v3 Twill Capsule
## Installing
### Require the Composer package:
``` bash
composer require area17/twill-google-recaptcha
```### Publish the configuration
``` bash
php artisan vendor:publish --provider="A17\TwillGoogleRecaptcha\ServiceProvider"
```### Load Capsule helpers by adding calling the loader to your AppServiceProvider:
``` php
/**
* Register any application services.
*
* @return void
*/
public function register()
{
\A17\TwillGoogleRecaptcha\Services\Helpers::load();
}
```#### Create debugging routes to check if it's all good
```php
Route::prefix('/debug')->group(function () {
Route::get('/google-recaptcha-3', [A17\TwillGoogleRecaptcha\Http\Controllers\TwillGoogleRecaptchaFrontController::class, 'show'])->name(
'google-recaptcha.show',
);Route::post('/google-recaptcha-3', [A17\TwillGoogleRecaptcha\Http\Controllers\TwillGoogleRecaptchaFrontController::class, 'store'])->name(
'google-recaptcha.store',
);
});
```#### Translate validation messages on validation.php
```php
'google_recaptcha' => 'Failed invisible Google reCAPTCHA, please try again.',
```#### Sharing it in your views
To have a `$twillGoogleRecaptcha` shared on your views, you can call this helper on your `AppServiceProvider`:
``` php
\A17\TwillGoogleRecaptcha\Services\Helpers::viewShare()
```One possible example is to use `View::composer()` to load the needed variables into your views:
``` php
validate([
'g-recaptcha-response' => ['required', 'string', new GoogleRecaptchaValidator()],
]);
```## Contribute
Please contribute to this project by submitting pull requests.