Merge pull request #798 from xsbeats/feature/validation_required_with

Added required_with validation rule...
This commit is contained in:
Taylor Otwell 2012-07-06 18:11:19 -07:00
commit 430eeb6da1
2 changed files with 25 additions and 1 deletions

View File

@ -63,6 +63,9 @@ #### Validate that an attribute is present and is not an empty string:
'name' => 'required'
#### Validate that an attribute is present, when another attribute is present:
'last_name' => 'required_with:first_name'
<a name="rule-alpha"></a>
### Alpha, Alpha Numeric, & Alpha Dash

View File

@ -214,7 +214,7 @@ protected function validatable($rule, $attribute, $value)
*/
protected function implicit($rule)
{
return $rule == 'required' or $rule == 'accepted';
return $rule == 'required' or $rule == 'accepted' or $rule == 'required_with';
}
/**
@ -257,6 +257,27 @@ protected function validate_required($attribute, $value)
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.
*