Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/Illuminate/Validation/Concerns/ReplacesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,62 @@ protected function replaceRequiredWithoutAll($message, $attribute, $rule, $param
return $this->replaceRequiredWith($message, $attribute, $rule, $parameters);
}

/**
* Replace all place-holders for the prohibited_with rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return string
*/
protected function replaceProhibitedWith($message, $attribute, $rule, $parameters)
{
return str_replace(':values', implode(' / ', $this->getAttributeList($parameters)), $message);
}

/**
* Replace all place-holders for the prohibited_with_all rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return string
*/
protected function replaceProhibitedWithAll($message, $attribute, $rule, $parameters)
{
return $this->replaceProhibitedWith($message, $attribute, $rule, $parameters);
}

/**
* Replace all place-holders for the prohibited_without rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return string
*/
protected function replaceProhibitedWithout($message, $attribute, $rule, $parameters)
{
return $this->replaceProhibitedWith($message, $attribute, $rule, $parameters);
}

/**
* Replace all place-holders for the prohibited_without_all rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return string
*/
protected function replaceProhibitedWithoutAll($message, $attribute, $rule, $parameters)
{
return $this->replaceProhibitedWith($message, $attribute, $rule, $parameters);
}

/**
* Replace all place-holders for the size rule.
*
Expand Down
86 changes: 86 additions & 0 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,58 @@ public function validateProhibitedUnless($attribute, $value, $parameters)
return true;
}

/**
* Validate that an attribute does not exist when any other attribute exists.
*
* @param string $attribute
* @param mixed $value
* @param mixed $parameters
* @return bool
*/
public function validateProhibitedWith($attribute, $value, $parameters)
{
return ! $this->anyPassingRequired($parameters);
}

/**
* Validate that an attribute does not exist when all other attributes exist.
*
* @param string $attribute
* @param mixed $value
* @param mixed $parameters
* @return bool
*/
public function validateProhibitedWithAll($attribute, $value, $parameters)
{
return ! $this->allPassingRequired($parameters);
}

/**
* Validate that an attribute does not exist when another attribute does not exist.
*
* @param string $attribute
* @param mixed $value
* @param mixed $parameters
* @return bool
*/
public function validateProhibitedWithout($attribute, $value, $parameters)
{
return ! $this->anyFailingRequired($parameters);
}

/**
* Validate that an attribute does not exist when all other attributes do not exist.
*
* @param string $attribute
* @param mixed $value
* @param mixed $parameters
* @return bool
*/
public function validateProhibitedWithoutAll($attribute, $value, $parameters)
{
return $this->anyPassingRequired($parameters);
}

/**
* Indicate that an attribute should be excluded when another attribute has a given value.
*
Expand Down Expand Up @@ -1729,6 +1781,40 @@ protected function allFailingRequired(array $attributes)
return true;
}

/**
* Determine if any of the given attributes pass the required test.
*
* @param array $attributes
* @return bool
*/
protected function anyPassingRequired(array $attributes)
{
foreach ($attributes as $key) {
if ($this->validateRequired($key, $this->getValue($key))) {
return true;
}
}

return false;
}

/**
* Determine if all of the given attributes pass the required test.
*
* @param array $attributes
* @return bool
*/
protected function allPassingRequired(array $attributes)
{
foreach ($attributes as $key) {
if (! $this->validateRequired($key, $this->getValue($key))) {
return false;
}
}

return true;
}

/**
* Validate that two attributes match.
*
Expand Down
4 changes: 4 additions & 0 deletions src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ class Validator implements ValidatorContract
'Prohibited',
'ProhibitedIf',
'ProhibitedUnless',
'ProhibitedWith',
'ProhibitedWithAll',
'ProhibitedWithout',
'ProhibitedWithoutAll',
'Same',
'Unique',
];
Expand Down
Loading