【问题标题】:Laravel 5 mewebstudio/captcha not workingLaravel 5 mewebstudio/验证码不工作
【发布时间】:2016-04-18 09:51:49
【问题描述】:

我在使用 Laravel 5 mewebstudio/captcha 时遇到问题。

我安装了它,在我的页面上是验证码图片

echo captcha_img()
echo Form::text('captcha','',["class"=>"form-control","placeholder"=>trans('page.captcha')]);

这很好用。

但问题在于验证,验证表单后我收到一条关于验证码不正确的消息。

我的验证码:

    if (Request::isMethod('post')){

        //$data = Input::except(array('_token'));
        $data = Input::all();
        $rule = array(
            'name' => 'required',
            'firstname' => 'required',
            'bdate' => 'required',
            'email' => 'required|email',
            'password' => 'required|min:6|same:password_repeat',
            'password_repeat' => 'required|min:6',
            'captcha' => 'required|captcha'

        );

        $validator = Validator::make($data, $rule);

        if ($validator->fails()) {

            $errors = $validator->messages();

        }
    }

我认为验证码会话不起作用,因为在转储会话之后我没有应该放入会话中的验证码密钥(我在 Captcha.php 中找到)

      $this->session->put('captcha', [
        'sensitive' => $this->sensitive,
        'key'       => $this->hasher->make($this->sensitive ? $bag : $this->str->lower($bag))
    ]);

【问题讨论】:

    标签: php session laravel-5 captcha laravel-5.2


    【解决方案1】:

    在 Laravel 5.2 中,您需要将 CaptchaServiceProvider 中的第 29 行更改为

    $this->app['router']->group(['middleware' => 'web'], function () {
                $this->app['router']->get('captcha/{config?}', '\Mews\Captcha\CaptchaController@getCaptcha');
            });
    

    【讨论】:

      【解决方案2】:

      我解决了这个问题。

      在 Laravel 5.2 中,您需要更改 CaptchaServiceProvider to 中的第 26 行

      $this->app['router']->get('captcha/{config?}', \Mews\Captcha\CaptchaController@getCaptcha')->middleware('web');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-01-22
        • 1970-01-01
        • 2015-08-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多