felipetti/captcha

此包用于将验证码服务集成到Laravel项目中

v2.0.4 2024-04-12 22:31 UTC

This package is auto-updated.

Last update: 2024-09-12 23:28:17 UTC


README

它做什么

此包允许您将CAPTCHA V2或V3集成到您的Laravel应用程序中。

安装

composer require felipetti/captcha

使用说明

首先发布配置文件

php artisan vendor:publish --tag=captcha

配置文件名为captcha.php,位于根目录的config文件夹中。打开文件,将Google提供的密钥放入“secret_key”字段。

/*
    |--------------------------------------------------------------------------
    | Secret Key
    |--------------------------------------------------------------------------
    |
    | This is the CAPTCHA key that only back-end has.
    |
    */

    'secret_key' => ''

有三种集成验证码服务的方式,假设$captcha是前端发送验证码响应的字段

表单请求方式

    use Felipetti\Captcha\Rule\CaptchaVerification;
    
    public function rules()
    {
        $captcha = ['required', 'string', new CaptchaVerification];
        
        return compact('captcha');
    }

请求验证方式

假设我们有一个验证码控制器,我们想在其中进行验证

use Felipetti\Captcha\Rule\CaptchaVerification;
use Illuminate\Http\Request;

class CaptchaController extends Controller
{
    public function __invoke(Request $request)
    {
        $request->validate(
            ['captcha' => [new CaptchaVerification]]
        );

        //...
    }
}

验证器方式

use Felipetti\Captcha\Rule\CaptchaVerification;
use Illuminate\Support\Facades\Validator;
use Illuminate\Http\Request;

class CaptchaController extends Controller
{
    public function __invoke(Request $request)
    {
        $rules  = ['captcha' => [new CaptchaVerification]];

        Validator::make($request->only('captcha'), $rules)->validate();

        //...
    }
}

配置

配置文件中的解释相当清晰,如果您有任何问题,请发送电子邮件至 guill388@hotmail.com

评论

如果您喜欢这个包,请给它加星,这会对我有很大帮助。

安全

如果您发现任何安全相关的问题,请通过上述电子邮件而不是问题跟踪器联系我。

许可证

MIT许可证(MIT)。