Reputation: 3128
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!
Upvotes: 1
Views: 2009
Reputation: 10533
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.
Upvotes: 2