Skip to content

Commit

Permalink
Revert "[6.x] Fix required_if boolean validation (#36967)"
Browse files Browse the repository at this point in the history
This reverts commit e1f36fa.
  • Loading branch information
driesvints committed Apr 13, 2021
1 parent e1f36fa commit 63655bf
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 23 deletions.
13 changes: 1 addition & 12 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Expand Up @@ -1475,24 +1475,13 @@ protected function prepareValuesAndOther($parameters)

$values = array_slice($parameters, 1);

if ($this->shouldConvertToBoolean($parameters[0]) || is_bool($other)) {
if (is_bool($other)) {
$values = $this->convertValuesToBoolean($values);
}

return [$values, $other];
}

/**
* Check if parameter should be converted to boolean.
*
* @param string $parameter
* @return bool
*/
protected function shouldConvertToBoolean($parameter)
{
return in_array('boolean', Arr::get($this->rules, $parameter, []));
}

/**
* Convert the given values to boolean if they are string "true" / "false".
*
Expand Down
11 changes: 0 additions & 11 deletions tests/Validation/ValidationValidatorTest.php
Expand Up @@ -1090,17 +1090,6 @@ public function testRequiredIf()
$v = new Validator($trans, ['first' => 'dayle', 'last' => ''], ['last' => 'RequiredIf:first,taylor,dayle']);
$this->assertFalse($v->passes());
$this->assertSame('The last field is required when first is dayle.', $v->messages()->first('last'));

$trans = $this->getIlluminateArrayTranslator();
$trans->addLines(['validation.required_if' => 'The :attribute field is required when :other is :value.'], 'en');
$v = new Validator($trans, ['foo' => 0], [
'foo' => 'required|boolean',
'bar' => 'required_if:foo,true',
'baz' => 'required_if:foo,false',
]);
$this->assertTrue($v->fails());
$this->assertCount(1, $v->messages());
$this->assertSame('The baz field is required when foo is 0.', $v->messages()->first('baz'));
}

public function testRequiredUnless()
Expand Down

0 comments on commit 63655bf

Please sign in to comment.