Composer will manage this automatically for you, but these are the supported versions between Twill and this package.
Twill Version | HTTP Basic Auth Capsule |
---|---|
3.x | 2.x |
2.x | 1.x |
composer require area17/twill-google-recaptcha
php artisan vendor:publish --provider="A17\TwillGoogleRecaptcha\ServiceProvider"
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',
);
});
'google_recaptcha' => 'Failed invisible Google reCAPTCHA, please try again.',
To have a $twillGoogleRecaptcha
shared on your views, you can call this helper on your AppServiceProvider
:
\A17\TwillGoogleRecaptcha\Services\Helpers::viewShare()
One possible example is to use View::composer()
to load the needed variables into your views:
<?php
namespace App\Providers;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use A17\TwillGoogleRecaptcha\Services\Helpers as TwillGoogleRecaptchaHelpers;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
View::composer('*', function () {
\A17\TwillGoogleRecaptcha\Services\Helpers::viewShare();
});
}
}
Head to: http://site.com/debug/google-recaptcha-3
TWILL_GOOGLE_RECAPTCHA_SITE_KEY=<public key>
TWILL_GOOGLE_RECAPTCHA_PRIVATE_KEY=<private key>
TWILL_GOOGLE_RECAPTCHA_ENABLED=true
File: app/Twill/Capsules/GoogleRecaptchas/resources/views/front/form.blade.php
use A17\TwillGoogleRecaptcha\Support\Validator as GoogleRecaptchaValidator;
$request->validate([
'g-recaptcha-response' => ['required', 'string', new GoogleRecaptchaValidator()],
]);
Please contribute to this project by submitting pull requests.