diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index b39602c2adff..62e26af27f74 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -375,9 +375,15 @@ protected function validateDifferent($attribute, $value, $parameters) { $this->requireParameterCount(1, $parameters, 'different'); - $other = Arr::get($this->data, $parameters[0]); + foreach ($parameters as $parameter) { + $other = Arr::get($this->data, $parameter); + + if (is_null($other) || $value === $other) { + return false; + } + } - return isset($other) && $value !== $other; + return true; } /** diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index c4652f68f1fe..ae08d2899861 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -1012,6 +1012,15 @@ public function testValidateDifferent() $v = new Validator($trans, ['foo' => '1e2', 'baz' => '100'], ['foo' => 'Different:baz']); $this->assertTrue($v->passes()); + + $v = new Validator($trans, ['foo' => 'bar', 'fuu' => 'baa', 'baz' => 'boom'], ['foo' => 'Different:fuu,baz']); + $this->assertTrue($v->passes()); + + $v = new Validator($trans, ['foo' => 'bar', 'baz' => 'boom'], ['foo' => 'Different:fuu,baz']); + $this->assertFalse($v->passes()); + + $v = new Validator($trans, ['foo' => 'bar', 'fuu' => 'bar', 'baz' => 'boom'], ['foo' => 'Different:fuu,baz']); + $this->assertFalse($v->passes()); } public function testValidateAccepted()