diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index 28371530e633..98eda67680aa 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -891,7 +891,9 @@ public function validateGt($attribute, $value, $parameters) return $this->getSize($attribute, $value) > $parameters[0]; } - $this->requireSameType($value, $comparedToValue); + if (! $this->isSameType($value, $comparedToValue)) { + return false; + } return $this->getSize($attribute, $value) > $this->getSize($attribute, $comparedToValue); } @@ -916,7 +918,9 @@ public function validateLt($attribute, $value, $parameters) return $this->getSize($attribute, $value) < $parameters[0]; } - $this->requireSameType($value, $comparedToValue); + if (! $this->isSameType($value, $comparedToValue)) { + return false; + } return $this->getSize($attribute, $value) < $this->getSize($attribute, $comparedToValue); } @@ -941,7 +945,9 @@ public function validateGte($attribute, $value, $parameters) return $this->getSize($attribute, $value) >= $parameters[0]; } - $this->requireSameType($value, $comparedToValue); + if (! $this->isSameType($value, $comparedToValue)) { + return false; + } return $this->getSize($attribute, $value) >= $this->getSize($attribute, $comparedToValue); } @@ -966,7 +972,9 @@ public function validateLte($attribute, $value, $parameters) return $this->getSize($attribute, $value) <= $parameters[0]; } - $this->requireSameType($value, $comparedToValue); + if (! $this->isSameType($value, $comparedToValue)) { + return false; + } return $this->getSize($attribute, $value) <= $this->getSize($attribute, $comparedToValue); } @@ -1721,19 +1729,15 @@ public function requireParameterCount($count, $parameters, $rule) } /** - * Require comparison values to be of the same type. + * Check if the parameters are of the same type. * * @param mixed $first * @param mixed $second - * @return void - * - * @throws \InvalidArgumentException + * @return bool */ - protected function requireSameType($first, $second) + protected function isSameType($first, $second) { - if (gettype($first) != gettype($second)) { - throw new InvalidArgumentException('The values under comparison must be of the same type'); - } + return gettype($first) == gettype($second); } /** diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index bea82017deaf..a615df2e37db 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -1085,6 +1085,12 @@ public function testGreaterThan() $v = new Validator($trans, ['lhs' => 15, 'rhs' => 10], ['lhs' => 'numeric|gt:rhs']); $this->assertTrue($v->passes()); + $v = new Validator($trans, ['lhs' => 15, 'rhs' => 'string'], ['lhs' => 'numeric|gt:rhs']); + $this->assertTrue($v->fails()); + + $v = new Validator($trans, ['lhs' => 15], ['lhs' => 'numeric|gt:rhs']); + $this->assertTrue($v->fails()); + $v = new Validator($trans, ['lhs' => 'longer string', 'rhs' => 'string'], ['lhs' => 'gt:rhs']); $this->assertTrue($v->passes()); @@ -1108,6 +1114,12 @@ public function testLessThan() $v = new Validator($trans, ['lhs' => 15, 'rhs' => 10], ['lhs' => 'numeric|lt:rhs']); $this->assertTrue($v->fails()); + $v = new Validator($trans, ['lhs' => 15, 'rhs' => 'string'], ['lhs' => 'numeric|lt:rhs']); + $this->assertTrue($v->fails()); + + $v = new Validator($trans, ['lhs' => 15], ['lhs' => 'numeric|lt:rhs']); + $this->assertTrue($v->fails()); + $v = new Validator($trans, ['lhs' => 'longer string', 'rhs' => 'string'], ['lhs' => 'lt:rhs']); $this->assertTrue($v->fails()); @@ -1131,6 +1143,12 @@ public function testGreaterThanOrEqual() $v = new Validator($trans, ['lhs' => 15, 'rhs' => 15], ['lhs' => 'numeric|gte:rhs']); $this->assertTrue($v->passes()); + $v = new Validator($trans, ['lhs' => 15, 'rhs' => 'string'], ['lhs' => 'numeric|gte:rhs']); + $this->assertTrue($v->fails()); + + $v = new Validator($trans, ['lhs' => 15], ['lhs' => 'numeric|gte:rhs']); + $this->assertTrue($v->fails()); + $v = new Validator($trans, ['lhs' => 'longer string', 'rhs' => 'string'], ['lhs' => 'gte:rhs']); $this->assertTrue($v->passes()); @@ -1154,6 +1172,12 @@ public function testLessThanOrEqual() $v = new Validator($trans, ['lhs' => 15, 'rhs' => 15], ['lhs' => 'numeric|lte:rhs']); $this->assertTrue($v->passes()); + $v = new Validator($trans, ['lhs' => 15, 'rhs' => 'string'], ['lhs' => 'numeric|lte:rhs']); + $this->assertTrue($v->fails()); + + $v = new Validator($trans, ['lhs' => 15], ['lhs' => 'numeric|lte:rhs']); + $this->assertTrue($v->fails()); + $v = new Validator($trans, ['lhs' => 'longer string', 'rhs' => 'string'], ['lhs' => 'lte:rhs']); $this->assertTrue($v->fails());