Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 mewebstudio/captcha not working

I have got problem with Laravel 5 mewebstudio/captcha.

I install it and on my page is captcha image

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

This works fine.

But the problem is with the validation, after the validation form I get a message about incorrect captcha.

My validation code:

    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();

        }
    }

I think captcha session is not working because after dump session I don't have captcha key which should be put in session (I found in Captcha.php )

      $this->session->put('captcha', [
        'sensitive' => $this->sensitive,
        'key'       => $this->hasher->make($this->sensitive ? $bag : $this->str->lower($bag))
    ]);
like image 387
Olbrych Avatar asked Dec 03 '25 07:12

Olbrych


1 Answers

In Laravel 5.2 you need to change line 29 in CaptchaServiceProvider to

$this->app['router']->group(['middleware' => 'web'], function () {
            $this->app['router']->get('captcha/{config?}', '\Mews\Captcha\CaptchaController@getCaptcha');
        });
like image 169
Dmitry Avatar answered Dec 04 '25 20:12

Dmitry