To install, simply add it
to your composer.json
file:
{
"require": {
"huangdijia/laravel-recaptcha-v3": "^3.0"
}
}
And run composer to update your dependencies:
composer update
Or you can simply run
composer require huangdijia/laravel-recaptcha-v3
Publish configuration file to your config
folder with command:
php artisan vendor:publish --provider="Huangdijia\Recaptcha\RecaptchaServiceProvider" --tag=config
// default
@recaptcha_field()
// custom
@recaptcha_field(['site_key'=>'your_key', 'name'=>'input_name'])
Must add after @recaptcha_field()
Recaptcha v3 works best when it is loaded on every page to get the most context about interactions. Therefore, add to your header or footer template:
// default
@recaptcha_initjs()
// custom
@recaptcha_initjs(['site_key'=>'your_key', 'action' => 'action_name', 'name'=>'input_name'])
Use as regular validation rule recaptcha:{ACTION},{SCORE},{HOSTNAME}
like:
Validator::make($request->all(), [
'g-recaptcha-response' => 'required|recaptcha:register,0.5,www.a.com',
// or
// 'g-recaptcha-response' => 'required|recaptcha',
]);
Set $routeMiddleware
$routeMiddleware = [
// ...
'recaptcha' => Huangdijia\Recaptcha\Middleware\ReCaptcha::class,
];
Use with route
Route::get('/path')->middleware('recaptcha');
Route::get('/path')->middleware('recaptcha:{ACTION},{SCORE},{HOSTNAME}');
Hidden ReCAPTCHA
.grecaptcha-badge {
display: none;
}