1

I am trying to implement and use a couple of my own custom validation methods in a class called WBValidation that extends Illuminate\Validation\Validator

I have this method validateCombinedRequired:

 class WBValidation extends Illuminate\Validation\Validator{


     public function validateCombinedRequired($attribute,$value,$parameters){
            return (    $this->validateRequired($attribute,$value)  )
            and    (    $this->validateRequired($parameters[0],$this->data[$parameters[0]])     );
        }
}

I have placed this class in the libraries folder. For the framework to automatically pick up this class, it might be getting picked up because I can see it in autoload_classmap.php ( I might be wrong ).

When I try to use it in my model, I am getting this error which says BadMethodCallException","message":"Method [validateCombinedRequired] does not exist:

class UserModel extends Eloquent{
    protected $table='user';
    public static function VerifyUserAdd($data){


        $rules = array('password'=>'required|combined_required:repassword');

        // stuff

        return Validator::make($data,$rules,$errormessages);
    }
}

Is there anything else I should be doing? Please help me!

1 Answer 1

2

You need to register your custom Validator extension:

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

I suggest reading the documentation as it covers several was of adding your own custom validation rules.

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

2 Comments

You could do it in your start/global.php.
Awesome, that worked. By the way, is there a neater way to do custom validation, besides validator:extend({});?

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.