Skip to content

Commit 450493a

Browse files
committed
Merge branch 'master' into 3.1-merge
2 parents 50b2c6d + c45e1ed commit 450493a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/Concerns/ValidatesAttributes.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,10 @@ public function validateGt(string $attribute, $value, array $parameters): bool
533533
return $this->getSize($attribute, $value) > $parameters[0];
534534
}
535535

536+
if ($this->hasRule($attribute, $this->numericRules) && is_numeric($value) && is_numeric($comparedToValue)) {
537+
return $value > $comparedToValue;
538+
}
539+
536540
if (! $this->isSameType($value, $comparedToValue)) {
537541
return false;
538542
}
@@ -557,6 +561,10 @@ public function validateLt(string $attribute, $value, array $parameters): bool
557561
return $this->getSize($attribute, $value) < $parameters[0];
558562
}
559563

564+
if ($this->hasRule($attribute, $this->numericRules) && is_numeric($value) && is_numeric($comparedToValue)) {
565+
return $value < $comparedToValue;
566+
}
567+
560568
if (! $this->isSameType($value, $comparedToValue)) {
561569
return false;
562570
}
@@ -581,6 +589,10 @@ public function validateGte(string $attribute, $value, array $parameters): bool
581589
return $this->getSize($attribute, $value) >= $parameters[0];
582590
}
583591

592+
if ($this->hasRule($attribute, $this->numericRules) && is_numeric($value) && is_numeric($comparedToValue)) {
593+
return $value >= $comparedToValue;
594+
}
595+
584596
if (! $this->isSameType($value, $comparedToValue)) {
585597
return false;
586598
}
@@ -605,6 +617,10 @@ public function validateLte(string $attribute, $value, array $parameters): bool
605617
return $this->getSize($attribute, $value) <= $parameters[0];
606618
}
607619

620+
if ($this->hasRule($attribute, $this->numericRules) && is_numeric($value) && is_numeric($comparedToValue)) {
621+
return $value <= $comparedToValue;
622+
}
623+
608624
if (! $this->isSameType($value, $comparedToValue)) {
609625
return false;
610626
}

tests/Cases/ValidationValidatorTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,9 @@ public function testValidateGtPlaceHolderIsReplacedProperly()
16941694
$this->assertFalse($v->passes());
16951695
$this->assertEquals(5, $v->messages()->first('items'));
16961696

1697+
$v = new Validator($trans, ['items' => '26', 'more' => 5], ['items' => 'gt:more']);
1698+
$this->assertTrue($v->passes());
1699+
16971700
$v = new Validator($trans, ['items' => 'abc', 'more' => 'abcde'], ['items' => 'gt:more']);
16981701
$this->assertFalse($v->passes());
16991702
$this->assertEquals(5, $v->messages()->first('items'));
@@ -1731,6 +1734,9 @@ public function testValidateLtPlaceHolderIsReplacedProperly()
17311734
$this->assertFalse($v->passes());
17321735
$this->assertEquals(2, $v->messages()->first('items'));
17331736

1737+
$v = new Validator($trans, ['items' => '5', 'less' => 26], ['items' => 'numeric|lt:less']);
1738+
$this->assertTrue($v->passes());
1739+
17341740
$v = new Validator($trans, ['items' => 'abc', 'less' => 'ab'], ['items' => 'lt:less']);
17351741
$this->assertFalse($v->passes());
17361742
$this->assertEquals(2, $v->messages()->first('items'));
@@ -1768,6 +1774,9 @@ public function testValidateGtePlaceHolderIsReplacedProperly()
17681774
$this->assertFalse($v->passes());
17691775
$this->assertEquals(5, $v->messages()->first('items'));
17701776

1777+
$v = new Validator($trans, ['items' => '26', 'more' => 26], ['items' => 'numeric|gte:more']);
1778+
$this->assertTrue($v->passes());
1779+
17711780
$v = new Validator($trans, ['items' => 'abc', 'more' => 'abcde'], ['items' => 'gte:more']);
17721781
$this->assertFalse($v->passes());
17731782
$this->assertEquals(5, $v->messages()->first('items'));
@@ -1805,6 +1814,9 @@ public function testValidateLtePlaceHolderIsReplacedProperly()
18051814
$this->assertFalse($v->passes());
18061815
$this->assertEquals(2, $v->messages()->first('items'));
18071816

1817+
$v = new Validator($trans, ['items' => 5, 'less' => '26'], ['items' => 'numeric|lte:less']);
1818+
$this->assertTrue($v->passes());
1819+
18081820
$v = new Validator($trans, ['items' => 'abc', 'less' => 'ab'], ['items' => 'lte:less']);
18091821
$this->assertFalse($v->passes());
18101822
$this->assertEquals(2, $v->messages()->first('items'));

0 commit comments

Comments
 (0)