tigusigalpa / yandex-captcha-filament
Yandex SmartCaptcha integration for Laravel Filament v4. Form field component with validation support.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/tigusigalpa/yandex-captcha-filament
Requires
- php: ^8.1
- filament/filament: ^4.0
- illuminate/support: ^10.0|^11.0|^12.0
- tigusigalpa/yandex-smartcaptcha-php: ^1.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^10.0|^11.0
- squizlabs/php_codesniffer: ^3.6
README
π‘οΈ Filament Yandex Captcha
Yandex SmartCaptcha Integration for Laravel Filament v4
Protect your Filament forms with Yandex SmartCaptcha - the modern, user-friendly CAPTCHA solution
π Quick Start β’ π Documentation β’ π‘ Examples β’ π€ Contributing
β¨ Features
π Table of Contents
- Requirements
- Installation
- Quick Start
- Configuration
- Usage Examples
- Advanced Features
- API Reference
- Troubleshooting
- Contributing
- License
π― Requirements
| Requirement | Version |
|---|---|
| PHP | ^8.1 |
| Laravel | ^10.0 | ^11.0 | ^12.0 |
| Filament | ^4.0 |
| Base Package | tigusigalpa/yandex-smartcaptcha-php ^1.0 |
π¦ Installation
Step 1: Install via Composer
composer require tigusigalpa/yandex-captcha-filament
Step 2: Publish Configuration
php artisan vendor:publish --tag=yandex-captcha-filament-config
This creates config/yandex-captcha-filament.php with all available options.
Step 3: Get Your Yandex SmartCaptcha Keys
3.1. Create Yandex Cloud Account
- Visit Yandex Cloud Console
- Sign in or create a new account
- Ensure you have an active billing account (free tier available)
3.2. Create Your Captcha
- Navigate to Yandex SmartCaptcha service
- Click Create captcha
- Configure your captcha:
- Name:
my-app-captcha(or any name you prefer) - Domains: Add your domain (e.g.,
example.com) - Pre-check type: Checkbox or Slider
- Challenge type: Image-text task
- Complexity: Easy, Medium, or Hard
- Name:
- Click Create
3.3. Copy Your Keys
- Open your created captcha
- Go to Overview tab
- Copy both keys:
- Client Key (for frontend widget)
- Server Key (for backend validation)
Step 4: Configure Environment
Add to your .env file:
YANDEX_CAPTCHA_CLIENT_KEY=your-client-key-here YANDEX_CAPTCHA_SECRET_KEY=your-secret-key-here YANDEX_CAPTCHA_LANGUAGE=en YANDEX_CAPTCHA_THEME=light
π Quick Start
Basic Usage
Add the captcha field to any Filament form:
use Tigusigalpa\FilamentYandexCaptcha\Forms\Components\YandexCaptcha; public static function form(Form $form): Form { return $form ->schema([ TextInput::make('name') ->required(), TextInput::make('email') ->email() ->required(), YandexCaptcha::make('captcha') ->label('Verification') ->required(), ]); }
That's it! π The captcha will automatically:
- β Render the widget
- β Validate user input
- β Handle errors
- β Support themes
βοΈ Configuration
Environment Variables
# Required YANDEX_CAPTCHA_CLIENT_KEY=your-client-key YANDEX_CAPTCHA_SECRET_KEY=your-secret-key # Optional YANDEX_CAPTCHA_LANGUAGE=en # ru, en, be, kk, tt, uk, uz, tr YANDEX_CAPTCHA_THEME=light # light, dark YANDEX_CAPTCHA_TEST_MODE=prod # prod, force_pass, force_fail YANDEX_CAPTCHA_LOGGING=false # Enable error logging
Configuration File
The config/yandex-captcha-filament.php file provides full control:
return [ 'client_key' => env('YANDEX_CAPTCHA_CLIENT_KEY'), 'secret_key' => env('YANDEX_CAPTCHA_SECRET_KEY'), 'language' => env('YANDEX_CAPTCHA_LANGUAGE', 'en'), 'theme' => env('YANDEX_CAPTCHA_THEME', 'light'), 'test_mode' => env('YANDEX_CAPTCHA_TEST_MODE', 'prod'), 'logging' => [ 'enabled' => env('YANDEX_CAPTCHA_LOGGING', false), 'channel' => env('YANDEX_CAPTCHA_LOG_CHANNEL', 'stack'), ], ];
π‘ Usage Examples
1οΈβ£ Contact Form
use Tigusigalpa\FilamentYandexCaptcha\Forms\Components\YandexCaptcha; public static function form(Form $form): Form { return $form ->schema([ TextInput::make('name')->required(), TextInput::make('email')->email()->required(), Textarea::make('message')->required()->rows(5), YandexCaptcha::make('captcha') ->label('Security Check'), ]); }
2οΈβ£ Login Form with Captcha
use App\Filament\Pages\Auth\Login as BaseLogin; use Tigusigalpa\FilamentYandexCaptcha\Forms\Components\YandexCaptcha; class Login extends BaseLogin { public function form(Form $form): Form { return $form ->schema([ $this->getEmailFormComponent(), $this->getPasswordFormComponent(), $this->getRememberFormComponent(), YandexCaptcha::make('captcha') ->label('Security Verification'), ]); } }
Register in your Panel provider:
->login(Login::class)
3οΈβ£ Advanced Configuration
YandexCaptcha::make('captcha') ->label('Verify you are human') ->clientKey('custom-client-key') // Override config ->secretKey('custom-secret-key') // Override config ->language('ru') // Set language ->theme('dark') // Set theme ->invisible() // Invisible mode ->hideAfterValidation() // Hide after success ->callback('onCaptchaSuccess') // Success callback ->errorCallback('onCaptchaError') // Error callback ->testMode('force_pass'); // Test mode
4οΈβ£ Invisible Captcha
Perfect for newsletter subscriptions and simple forms:
YandexCaptcha::make('captcha') ->invisible() // No visible widget ->hideAfterValidation() // Clean UI ->required();
5οΈβ£ Custom JavaScript Callbacks
YandexCaptcha::make('captcha') ->callback('onSuccess') ->errorCallback('onError') ->networkErrorCallback('onNetworkError');
Add JavaScript functions:
<script> function onSuccess(token) { console.log('Captcha verified!', token); // Your custom logic } function onError() { console.error('Captcha failed!'); } function onNetworkError() { console.error('Network error!'); } </script>
π¨ Advanced Features
Supported Languages
| Language | Code | Language | Code |
|---|---|---|---|
| π·πΊ Russian | ru |
πΊπ¦ Ukrainian | uk |
| π¬π§ English | en |
πΊπΏ Uzbek | uz |
| π§πΎ Belarusian | be |
πΉπ· Turkish | tr |
| π°πΏ Kazakh | kk |
π·πΊ Tatar | tt |
Theme Support
// Light theme (default) YandexCaptcha::make('captcha')->theme('light'); // Dark theme YandexCaptcha::make('captcha')->theme('dark');
Test Modes
Perfect for development and testing:
// Always pass validation YandexCaptcha::make('captcha')->testMode('force_pass'); // Always fail validation YandexCaptcha::make('captcha')->testMode('force_fail'); // Normal operation YandexCaptcha::make('captcha')->testMode('prod');
Or via environment:
YANDEX_CAPTCHA_TEST_MODE=force_pass
Custom Validation Messages
Publish translations:
php artisan vendor:publish --tag=yandex-captcha-filament-translations
Edit resources/lang/vendor/yandex-captcha-filament/en/validation.php:
return [ 'required' => 'Please complete the captcha.', 'failed' => 'Captcha verification failed.', 'error' => 'An error occurred during verification.', 'config_error' => 'Captcha is not configured properly.', ];
Custom Views
Publish views for full customization:
php artisan vendor:publish --tag=yandex-captcha-filament-views
Edit resources/views/vendor/yandex-captcha-filament/forms/components/yandex-captcha.blade.php
π API Reference
YandexCaptcha Component Methods
| Method | Description | Example |
|---|---|---|
clientKey(string) |
Set client key | ->clientKey('key') |
secretKey(string) |
Set secret key | ->secretKey('key') |
language(string) |
Set widget language | ->language('ru') |
theme(string) |
Set theme (light/dark) | ->theme('dark') |
invisible(bool) |
Enable invisible mode | ->invisible() |
hideAfterValidation(bool) |
Hide after success | ->hideAfterValidation() |
callback(string) |
Success callback | ->callback('onSuccess') |
errorCallback(string) |
Error callback | ->errorCallback('onError') |
networkErrorCallback(string) |
Network error callback | ->networkErrorCallback('onNetworkError') |
testMode(string) |
Set test mode | ->testMode('force_pass') |
Validation Rule
Use the validation rule separately in any Laravel form:
use Tigusigalpa\FilamentYandexCaptcha\Rules\YandexCaptchaRule; $request->validate([ 'captcha' => ['required', new YandexCaptchaRule()], ]);
π§ Troubleshooting
Captcha Widget Not Showing
Possible causes:
-
β Invalid client key
# Check your .env file YANDEX_CAPTCHA_CLIENT_KEY=your-correct-key
-
β Domain not whitelisted
- Go to Yandex Cloud Console
- Add your domain to allowed domains
- Or disable domain verification
-
β JavaScript errors
- Open browser console (F12)
- Check for errors
- Ensure no ad blockers are interfering
Validation Always Fails
Possible causes:
-
β Invalid secret key
YANDEX_CAPTCHA_SECRET_KEY=your-correct-secret-key
-
β Token expired
- Tokens expire after 5 minutes
- User must complete captcha before submitting
-
β Network issues
- Enable logging to see detailed errors:
YANDEX_CAPTCHA_LOGGING=true
- Check Laravel logs:
storage/logs/laravel.log
Development Mode
For testing without actual captcha verification:
YANDEX_CAPTCHA_TEST_MODE=force_pass
β οΈ Remember to set back to prod in production!
Getting Help
- π Yandex SmartCaptcha Documentation
- π Report an Issue
- π¬ Discussions
- π§ Email: sovletig@gmail.com
π Project Structure
yandex-captcha-filament/
βββ π src/
β βββ FilamentYandexCaptchaPlugin.php # Main plugin
β βββ FilamentYandexCaptchaServiceProvider.php # Service provider
β βββ π Forms/Components/
β β βββ YandexCaptcha.php # Form field component
β βββ π Rules/
β βββ YandexCaptchaRule.php # Validation rule
β
βββ π resources/
β βββ π lang/ # Translations
β β βββ π en/
β β β βββ validation.php
β β βββ π ru/
β β βββ validation.php
β βββ π views/ # Blade templates
β βββ forms/components/
β βββ yandex-captcha.blade.php
β
βββ π config/
β βββ yandex-captcha-filament.php # Configuration
β
βββ π examples/ # Usage examples
β βββ BasicFormExample.php
β βββ AdvancedFormExample.php
β βββ LoginFormExample.php
β βββ RegistrationFormExample.php
β βββ InvisibleCaptchaExample.php
β βββ CustomCallbacksExample.php
β
βββ π README.md # This file
βββ π CHANGELOG.md # Version history
βββ π CONTRIBUTING.md # Contribution guide
βββ π LICENSE # MIT License
βββ π composer.json # Package metadata
π€ Contributing
We welcome contributions! Here's how you can help:
Ways to Contribute
- π Report bugs - Open an issue
- π‘ Suggest features - Share your ideas
- π Improve docs - Fix typos, add examples
- π§ Submit PRs - Fix bugs, add features
Development Setup
# Clone repository git clone https://github.com/tigusigalpa/yandex-captcha-filament.git cd yandex-captcha-filament # Install dependencies composer install # Run tests composer test # Check code style composer cs-check # Fix code style composer cs-fix # Run static analysis composer phpstan
Coding Standards
- β Follow PSR-12
- β Add tests for new features
- β Update documentation
- β Write clear commit messages
Pull Request Process
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
π License
This package is open-sourced software licensed under the MIT license.
MIT License
Copyright (c) 2025 Igor Sazonov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
π Acknowledgments
- Yandex Cloud for SmartCaptcha service
- Filament for the amazing admin panel
- Laravel for the fantastic framework
- All contributors and users of this package
π Links
- π¦ **Package **: tigusigalpa/yandex-captcha-filament
- π GitHub: tigusigalpa/yandex-captcha-filament
- π§ Base Package: tigusigalpa/yandex-smartcaptcha-php
- π Yandex SmartCaptcha: Official Documentation
- π¨ Filament: Official Website
π¨βπ» Author
Igor Sazonov
- π GitHub: @tigusigalpa
- π§ Email: sovletig@gmail.com
- π Website: GitHub Profile
π Support
If you find this package helpful, please consider:
- β Star the repository
- π Report bugs and issues
- π‘ Suggest new features
- π Improve documentation
- π Share with others
Made with β€οΈ for the Laravel & Filament community