- Add this file to application/libraries (or, if you are already extending the Validator class, add the contents there).
- Remove Validator alias from config/application.php in order to avoid conflicts.
- Add
"required_if_attribute" => "The :attribute field is required."
to application/language/[language]/validation.php.
Define the rule using:
required_if_attribute:[field],[operator],[value]
For example:
$rules = array(
'uses_framework' => 'required',
'preferred_framework' => 'required_if_attribute:uses_framework,==,1'
);
- ==
- !=
- ===
- !==
- <
- <=
-
-
=
This is, of course, easily extended.
I'm always getting this error: Undefined property: CustomValidator::$data when trying to use this validator... I also tried $this->getAttribute($parameters[0]) but this gives me the same error...
Why is this not working with me (I'm using Laravel 4.2) ?
maybe could somebody provide an example?