diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index 620bb1cd4934..8f567371e303 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -1592,7 +1592,11 @@ public function validateMissingWith($attribute, $value, $parameters) { $this->requireParameterCount(1, $parameters, 'missing_with'); - return ! Arr::hasAny($this->data, $parameters); + if (Arr::hasAny($this->data, $parameters)) { + return $this->validateMissing($attribute, $value, $parameters); + } + + return true; } /** @@ -1607,7 +1611,11 @@ public function validateMissingWithAll($attribute, $value, $parameters) { $this->requireParameterCount(1, $parameters, 'missing_with'); - return ! Arr::has($this->data, $parameters); + if (Arr::has($this->data, $parameters)) { + return $this->validateMissing($attribute, $value, $parameters); + } + + return true; } /** diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index dabf79f77149..d53b2899bc67 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -2361,6 +2361,9 @@ public function testValidateMissingWith() $trans = $this->getIlluminateArrayTranslator(); $trans->addLines(['validation.missing_with' => 'The :attribute field must be missing when :values is present.'], 'en'); + $v = new Validator($trans, ['bar' => '2'], ['foo' => 'missing_with:baz,bar']); + $this->assertTrue($v->passes()); + $v = new Validator($trans, ['foo' => 'yes', 'bar' => '2'], ['foo' => 'missing_with:baz,bar']); $this->assertFalse($v->passes()); $this->assertSame('The foo field must be missing when baz / bar is present.', $v->errors()->first('foo')); @@ -2400,6 +2403,9 @@ public function testValidateMissingWithAll() $trans = $this->getIlluminateArrayTranslator(); $trans->addLines(['validation.missing_with_all' => 'The :attribute field must be missing when :values are present.'], 'en'); + $v = new Validator($trans, ['bar' => '2', 'baz' => '2'], ['foo' => 'missing_with_all:baz,bar']); + $this->assertTrue($v->passes()); + $v = new Validator($trans, ['foo' => 'yes', 'bar' => '2', 'baz' => '2'], ['foo' => 'missing_with_all:baz,bar']); $this->assertFalse($v->passes()); $this->assertSame('The foo field must be missing when baz / bar are present.', $v->errors()->first('foo'));