yepsua / filament-captcha-field
为Filament Forms提供验证码字段
v0.1.1
2023-02-27 13:53 UTC
Requires
- php: ^8.0
- filament/forms: ^2.0
- illuminate/contracts: ^8.0|^9.0|^10.0
- mews/captcha: ^3.2
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2024-09-03 19:20:19 UTC
README
与mewebstudio/captcha轻松集成,适用于Filament表单。
需求
- PHP扩展:ext-gd
安装
通过Composer安装包
composer require yepsua/filament-captcha-field
发布mewebstudio/captcha配置文件
php artisan vendor:publish --provider="Mews\Captcha\CaptchaServiceProvider" --tag="config"
用法
您可以将验证码字段像其他任何Filament字段一样包含。
use Yepsua\Filament\Forms\Components\Captcha; ... protected function getFormSchema(): array { return [ Forms\Components\TextInput::make('username'), Forms\Components\TextInput::make('password')->type('password'), Captcha::make('captcha') ]; }
您还可以仅显示图片,并使用任何其他TextInput字段验证验证码
use Yepsua\Filament\Forms\Components\CaptchaImage; ... protected function getFormSchema(): array { return [ Forms\Components\TextInput::make('username'), Forms\Components\TextInput::make('password')->type('password'), Forms\Components\TextInput::make('captcha')->required()->rules('required|captcha'), CaptchaImage::make('captchaImg') ]; }
验证码默认使用flat
配置。您可以在文件中创建/更新验证码配置:config/captcha.php
。
您可以切换到任何其他可用的验证码配置,如math
配置
use Yepsua\Filament\Forms\Components\Captcha; ... protected function getFormSchema(): array { return [ Captcha::make('captcha')->config('math') ]; }
有关验证码配置的更多信息,请阅读mewebstudio/captcha文档。
翻译
此包和mewebstudio/captcha不提供验证码验证消息的翻译,但您可以自己翻译消息,只需在文件中添加项目:resources/lang/{lang}/validation.php
return [ ... 'captcha' => 'Invalid captcha.', ... ]
使用场景:在filament登录表单中添加验证码
- 扩展登录页面类以将新字段添加到表单中
<?php namespace App\Filament\Pages\Auth; use Filament\Http\Livewire\Auth\Login as BaseLoginPage; use Yepsua\Filament\Forms\Components\Captcha; class Login extends BaseLoginPage { protected function getFormSchema(): array { $formSchema = parent::getFormSchema(); $formSchema[] = Captcha::make('captcha'); return $formSchema; } }
- 使用新的登录页面而不是原始的filament页面。
return [ ... 'auth' => [ 'guard' => env('FILAMENT_AUTH_GUARD', 'web'), 'pages' => [ // 'login' => \Filament\Http\Livewire\Auth\Login::class, // <- Original form 'login' => \App\Filament\Pages\Auth\Login::class, // <- Form with captcha ], ], ... ]
- 完成。最后您可以在登录表单中测试验证码。
测试
composer test
更新日志
请参阅更新日志以获取最近更改的更多信息。
贡献
请参阅贡献指南以获取详细信息。
安全漏洞
请审查我们的安全策略以了解如何报告安全漏洞。
致谢
许可
MIT许可(MIT)。有关更多信息,请参阅许可文件。