laravel验证码mewebstudio/captcha使用笔记!

gitHub地址:https://github.com/mewebstudio/captcha

使用demo:
composer引入包:composer require mews/captcha

 "require": {
        // ...
        "mews/captcha": "^3.0", 
    },

因为使用的laravel5.8版本,所以:

#config/app.php
providers' => [
        // ...
        Mews\Captcha\CaptchaServiceProvider::class,
    ]

  'aliases' => [
        // ...
        'Captcha' => Mews\Captcha\Facades\Captcha::class,
    ]
发布配置文件php artisan vendor:publish,或者自建文件config/captcha.php,具体配置参考:vendor/mewebstudio/captcha/config/captcha.php
return [
    'default'   => [
        'length'    => 5,
        'width'     => 120,
        'height'    => 36,
        'quality'   => 90,
        'math'      => true, //Enable Math Captcha
    ],
    // ...
];
gitHub给出的demo,展示验证码图片和验证

    // [your site path]/Http/routes.php
    Route::any('captcha-test', function() {
        if (request()->getMethod() == 'POST') {
            $rules = ['captcha' => 'required|captcha'];
            $validator = validator()->make(request()->all(), $rules);
            if ($validator->fails()) {
                echo '

Incorrect!

'; } else { echo '

Matched :)

'; } } $form = '
'; $form .= ''; $form .= '

' . captcha_img() . '

'; $form .= '

'; $form .= '

'; $form .= '
'; return $form; });

返回不同类型和配置,用于不同场景

返回Image
captcha();
Captcha::create();
返回URL
captcha_src();
Captcha::src('default');
返回HTML
captcha_img();
Captcha::img();
使用自定义配置
captcha_img('flat');

Captcha::img('inverse');
form表单自刷新验证码使用demo:


你可能感兴趣的:(laravel验证码mewebstudio/captcha使用笔记!)