huangdijia / laravel-recaptcha-v3
recaptcha-v3 for laravel
Fund package maintenance!
huangdijia
hdj.me/sponsors
Installs: 9 021
Dependents: 0
Suggesters: 0
Security: 0
Stars: 20
Watchers: 2
Forks: 3
Open Issues: 0
Requires
- php: >=8.0
- google/recaptcha: ^1.2
- illuminate/console: ^9.0|^10.0|^11.0
- illuminate/support: ^9.0|^10.0|^11.0
Requires (Dev)
- huangdijia/php-coding-standard: ^1.1
- orchestra/testbench: ^7.0|^8.0|^9.0
- phpstan/phpstan: ^1.0
This package is auto-updated.
Last update: 2024-11-08 07:53:51 UTC
README
Installation
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
Usage
Forms
// default @recaptcha_field() // custom @recaptcha_field(['site_key'=>'your_key', 'name'=>'input_name'])
Init Recaptcha Javascript
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'])
Validation as regular validation rule
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', ]);
Validation as middleware
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; }