Commit 430eeb6d authored by Taylor Otwell's avatar Taylor Otwell

Merge pull request #798 from xsbeats/feature/validation_required_with

Added required_with validation rule...
parents 990f10f6 6881bdaf
...@@ -63,6 +63,9 @@ Now you are familiar with the basic usage of the Validator class. You're ready t ...@@ -63,6 +63,9 @@ Now you are familiar with the basic usage of the Validator class. You're ready t
'name' => 'required' 'name' => 'required'
#### Validate that an attribute is present, when another attribute is present:
'last_name' => 'required_with:first_name'
<a name="rule-alpha"></a> <a name="rule-alpha"></a>
### Alpha, Alpha Numeric, & Alpha Dash ### Alpha, Alpha Numeric, & Alpha Dash
......
...@@ -214,7 +214,7 @@ class Validator { ...@@ -214,7 +214,7 @@ class Validator {
*/ */
protected function implicit($rule) protected function implicit($rule)
{ {
return $rule == 'required' or $rule == 'accepted'; return $rule == 'required' or $rule == 'accepted' or $rule == 'required_with';
} }
/** /**
...@@ -257,6 +257,27 @@ class Validator { ...@@ -257,6 +257,27 @@ class Validator {
return true; return true;
} }
/**
* Validate that an attribute exists in the attributes array, if another
* attribute exists in the attributes array.
*
* @param string $attribute
* @param mixed $value
* @param array $parameters
* @return bool
*/
protected function validate_required_with($attribute, $value, $parameters)
{
$other = $parameters[0];
if ($this->validate_required($other, $this->attributes[$other]))
{
return $this->validate_required($attribute, $value);
}
return true;
}
/** /**
* Validate that an attribute has a matching confirmation attribute. * Validate that an attribute has a matching confirmation attribute.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment