czernika / laravel-captchas
Adds captchas to your Laravel web app
Requires
- guzzlehttp/guzzle: ^7.8
Requires (Dev)
- ergebnis/composer-normalize: ^2.42
- laravel/pint: ^1.14
- mockery/mockery: ^1.6
- orchestra/testbench: ^9.0
- pestphp/pest: ^2.34
- phpstan/phpstan: ^1.10
This package is auto-updated.
Last update: 2024-04-19 09:01:06 UTC
README
Adds captchas to your Laravel web app
Compatibility
Tested for Laravel versions 10 and 11
Version | PHP | Laravel |
---|---|---|
0.x | 8.1/8.2/8.3 | 10.x |
0.x | 8.2/8.3 | 11.x |
Roadmap
- - Yandex SmartCaptcha
- - Extended Yandex SmartCaptcha widget (You can use Vue3 SmartCaptcha component as a frontend HTML)
- - Google reCaptcha v2
- - Google reCaptcha v3
- - hCaptcha
Installation
composer require czernika/laravel-captchas
Next you need to add client and server keys into .env
file
CAPTCHA_CLIENT_KEY=
CAPTCHA_SECRET=
Add script tag into head
<head> {!! Captcha::js() !!} </head>
and HTML where captcha is needed. You may inject ot using html()
method (recommended)
{!! Captcha::html() !!}
Or you may render it as a component. Be aware this way every config option will be ignored and you need to pass it manually again, e.g.
<x-captcha data-sitekey="{{ config('captchas.keys.client') }}" data-callback="callback" data-hl="{{ app()->getLocale() }}" />
Configuration
Publish configuration file
php artisan vendor:publish --provider="Czernika\\Captchas\\CaptchaServiceProvider"
Every configuration option has self-explanatory comments
Events
Before and after validation request were sent there are two events
// accepts $token value \Czernika\Captchas\Events\SendingVerifyRequest => [ // ], // accepts $token value and response data \Czernika\Captchas\Events\VerifyRequestSent => [ // ],
Validation rule
After adding HTML you may verify captcha response by using validation rule
use Czernika\Captchas\Rules\CaptchaResponseRule; // Name of the key depends on Captcha type $request->validate([ 'smart-token' => ['required', 'string', new CaptchaResponseRule()], ]);
Captcha | Request key name to validate |
---|---|
yandex | smart-token |
extended_yandex | smart-token |
Testing
composer test
License
Open source under MIT License
TODO
- - Resolve attribute name to validate in request
- - Docs on Github Pages with examples
Extended Yandex SmartCaptcha
- - Pass JS callback function