Skip to content

Commit c29b004

Browse files
tillkrusstaylorotwell
authored andcommitted
support multiple fields to validateDifferent (#19637)
1 parent a05e9e2 commit c29b004

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/Illuminate/Validation/Concerns/ValidatesAttributes.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,15 @@ protected function validateDifferent($attribute, $value, $parameters)
375375
{
376376
$this->requireParameterCount(1, $parameters, 'different');
377377

378-
$other = Arr::get($this->data, $parameters[0]);
378+
foreach ($parameters as $parameter) {
379+
$other = Arr::get($this->data, $parameter);
380+
381+
if (is_null($other) || $value === $other) {
382+
return false;
383+
}
384+
}
379385

380-
return isset($other) && $value !== $other;
386+
return true;
381387
}
382388

383389
/**

tests/Validation/ValidationValidatorTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,15 @@ public function testValidateDifferent()
10121012

10131013
$v = new Validator($trans, ['foo' => '1e2', 'baz' => '100'], ['foo' => 'Different:baz']);
10141014
$this->assertTrue($v->passes());
1015+
1016+
$v = new Validator($trans, ['foo' => 'bar', 'fuu' => 'baa', 'baz' => 'boom'], ['foo' => 'Different:fuu,baz']);
1017+
$this->assertTrue($v->passes());
1018+
1019+
$v = new Validator($trans, ['foo' => 'bar', 'baz' => 'boom'], ['foo' => 'Different:fuu,baz']);
1020+
$this->assertFalse($v->passes());
1021+
1022+
$v = new Validator($trans, ['foo' => 'bar', 'fuu' => 'bar', 'baz' => 'boom'], ['foo' => 'Different:fuu,baz']);
1023+
$this->assertFalse($v->passes());
10151024
}
10161025

10171026
public function testValidateAccepted()

0 commit comments

Comments
 (0)