Skip to content

Commit

Permalink
Merge pull request #5262 from mohitmamoria/4.2
Browse files Browse the repository at this point in the history
Fixes the required_if messages if multiple values are passed
  • Loading branch information
taylorotwell committed Sep 8, 2014
2 parents d834d51 + a8e2249 commit fd6bfa4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1833,7 +1833,7 @@ protected function replaceRequiredWithoutAll($message, $attribute, $rule, $param
*/
protected function replaceRequiredIf($message, $attribute, $rule, $parameters)
{
$parameters[1] = $this->getDisplayableValue($parameters[0], $parameters[1]);
$parameters[1] = $this->getDisplayableValue($parameters[0], array_get($this->data, $parameters[0]));

$parameters[0] = $this->getAttribute($parameters[0]);

Expand Down
7 changes: 7 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,13 @@ public function testRequiredIf()
$trans = $this->getRealTranslator();
$v = new Validator($trans, array('first' => 'dayle', 'last' => 'rees'), array('last' => 'required_if:first,taylor,dayle'));
$this->assertTrue($v->passes());

// error message when passed multiple values (required_if:foo,bar,baz)
$trans = $this->getRealTranslator();
$trans->addResource('array', array('validation.required_if' => 'The :attribute field is required when :other is :value.'), 'en', 'messages');
$v = new Validator($trans, array('first' => 'dayle', 'last' => ''), array('last' => 'RequiredIf:first,taylor,dayle'));
$this->assertFalse($v->passes());
$this->assertEquals('The last field is required when first is dayle.', $v->messages()->first('last'));
}


Expand Down

0 comments on commit fd6bfa4

Please sign in to comment.