1. Go to this page and download the library: Download asignua/filament-captcha library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
asignua / filament-captcha example snippets
use Asignua\FilamentCaptcha\CaptchaPlugin;
$panel
->login()
->plugin(CaptchaPlugin::make()->login()->registration()->passwordReset());
use Asignua\FilamentCaptcha\Forms\Components\Captcha;
$schema->components([
TextInput::make('email')->email()-> ->driver('recaptcha_v3')
->captchaAction('contact') // v3 / Turnstile action name
->minScore(0.7)
->hostnames(['example.com'])
->theme('dark') // auto (default) | light | dark
->locale('uk');
use Asignua\FilamentCaptcha\Concerns\InteractsWithCaptcha;
class ContactForm extends Component
{
use InteractsWithCaptcha; // public string $captchaToken
public function submit(): void
{
$this->validateCaptcha(action: 'contact'); // throws ValidationException, resets the widget either way
// ...
}
}
use Asignua\FilamentCaptcha\Facades\Captcha;
$request->validate([
'captcha' => [Captcha::rule()->action('contact')->minScore(0.7)],
]);
class Login extends \Filament\Auth\Pages\Login
{
use \Asignua\FilamentCaptcha\Concerns\AddsCaptchaField;
protected function captchaScope(): string { return 'login'; }
}
use Asignua\FilamentCaptcha\Facades\Captcha;
Captcha::fake(); // widget not drawn, nothing sent, validation passes
Captcha::fake(passes: false); // validation fails
Captcha::extend('mine', fn (array $config, Factory $http) => new MyDriver($config, $http));