关于mews/captcha for laravel存在method [validateCaptcha] doesn't exists解决方法

1.controllers内容

$data = $request->all();
$rules = [
    'email' => 'required|email',
    'password' => 'required|between:6,20',
    'captcha' => 'required|captcha'
];
$validator = Validator::make($data, $rules);

2.在Providers/AppServiceProvider.php中增加:

...
use Validator;
...
public function boot()
{
    Validator::extend('captcha', function($attribute, $value, $parameters, $validator){
            return captcha_check($value);
     });
}

建议使用这种方法,可以避免修改插件源码以及git提交等带来的不便。

3.captcha验证始终返回false解决方法:

3.1.检查Kernel.php中粗体字部分是否已配置
protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,//加上此项配置
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
        ],
        'api' => [
            'throttle:60,1',
        ],
];
3.2.修改~/captcha/src/ServiceProvider.php第29行
$this->app['router']->get('captcha/{config}', 
                            function(Captcha $captcha, $config){
                                  return $captcha->create($config);
                            })->middleware('web');

4.项目地址

Laravel-Captcha

转载请注明原文地址:https://blog.keepchen.com/a/mews-captcha-exception.html