Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4bc806c

Browse files
committed
Allow multiple parameters for required_if
1 parent 254497b commit 4bc806c

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/Illuminate/Validation/Validator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,10 @@ protected function validateRequiredIf($attribute, $value, $parameters)
562562
{
563563
$this->requireParameterCount(2, $parameters, 'required_if');
564564

565-
if ($parameters[1] == array_get($this->data, $parameters[0]))
565+
$data = array_get($this->data, $parameters[0]);
566+
$values = array_slice($parameters, 1);
567+
568+
if (in_array($data, $values))
566569
{
567570
return $this->validateRequired($attribute, $value);
568571
}

tests/Validation/ValidationValidatorTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,14 @@ public function testRequiredIf()
345345
$trans = $this->getRealTranslator();
346346
$v = new Validator($trans, array('first' => 'taylor', 'last' => 'otwell'), array('last' => 'required_if:first,taylor'));
347347
$this->assertTrue($v->passes());
348+
349+
$trans = $this->getRealTranslator();
350+
$v = new Validator($trans, array('first' => 'taylor', 'last' => 'otwell'), array('last' => 'required_if:first,taylor,dayle'));
351+
$this->assertTrue($v->passes());
352+
353+
$trans = $this->getRealTranslator();
354+
$v = new Validator($trans, array('first' => 'dayle', 'last' => 'rees'), array('last' => 'required_if:first,taylor,dayle'));
355+
$this->assertTrue($v->passes());
348356
}
349357

350358

0 commit comments

Comments
 (0)