1

I am trying to register new custom validation but get this error:

Method [validateAlphaSpace] does not exist. [Laravel 5]

Here is my code:

CustomValidator.php

<?php namespace App;
use Illuminate\Validation\Validator;
class CustomValidator extends Validator {

    public function alpha_space($attribute, $value, $parameters)
    {
        return preg_match('/^[a-zA-Z0-9\s]+$/u', $value);
    }

}

ValidatorServicePorvider.php

<?php namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Validator;
use App\CustomValidator;
class ValidatorServicePorvider extends ServiceProvider {

 /**
  * Bootstrap any necessary services.
  *
  * @return void
  */
 public function boot()
 {

     Validator::resolver(function($translator, $data, $rules, $messages)
                        {
                            return new CustomValidator($translator, $data, $rules, $messages);
                        });
 }

 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {

 }

}

I also register provider inside app.php... Anyone can see what is problem?

2
  • 2
    the error already told you what is going on, you have to change your method name of "alpha_space" to "validateAlphaSpace" that is the laravel way to add custom validation Commented Jul 20, 2015 at 13:02
  • you might want to take look at Custom Validation Rules Commented Jul 20, 2015 at 13:04

1 Answer 1

1

Method in the custom validator class must be prefixed with "validate". In your case, try by renaming alpha_space method into validateAlphaSpace.

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

Comments

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.