3

I try to add new validation rule (Laravel 5.2) for google recaptcha and this rule not working. Can you explain me why? And how to fix it?

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Validator;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Validator::extend('recaptcha', function($attribute, $value, $parameters, $validator) {
            return false;
        });
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

-

class AuthController extends Controller
{
    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|confirmed|min:6',
            'g-recaptcha-response' => 'recaptcha|required',
        ]);
    }

Require rule working fine, recaptcha not. I try to do dump-autoload - no results.

Thank you very much :)

4
  • Did you register your service provider? Commented Mar 9, 2016 at 16:56
  • Try changing return false to return $value == 'recaptcha' Commented Mar 9, 2016 at 18:48
  • My new rule in AppServiceProvider and this provider already registered. Commented Mar 10, 2016 at 9:33
  • return $value == 'recaptcha' is worked for me, but this condition return false? why just false not working? Commented Mar 10, 2016 at 9:34

1 Answer 1

1

change recpatcha|required to captcha|required

assuming you're using https://github.com/anhskohbo/no-captcha

Sign up to request clarification or add additional context in comments.

1 Comment

I want to write my own script, but yes, already get a anhskohbo/no-captcha :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.