File tree 3 files changed +31
-1
lines changed
3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,20 @@ class Present extends Rule
20
20
*/
21
21
public function check ($ value ): bool
22
22
{
23
+ $ this ->setAttributeAsRequired ();
24
+
23
25
return $ this ->validation ->hasValue ($ this ->attribute ->getKey ());
24
26
}
27
+
28
+ /**
29
+ * Set attribute is required if $this->attribute is set
30
+ *
31
+ * @return void
32
+ */
33
+ protected function setAttributeAsRequired ()
34
+ {
35
+ if ($ this ->attribute ) {
36
+ $ this ->attribute ->setRequired (true );
37
+ }
38
+ }
25
39
}
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ public function check($value): bool
38
38
}
39
39
40
40
/**
41
- * Set attribute is required if $this->attribute is true
41
+ * Set attribute is required if $this->attribute is set
42
42
*
43
43
* @return void
44
44
*/
Original file line number Diff line number Diff line change @@ -681,6 +681,22 @@ public function testIgnoreNextRulesWhenImplicitRulesFails()
681
681
$ this ->assertNull ($ errors ->first ('must_accepted_field:min ' ));
682
682
}
683
683
684
+ public function testNextRulesAppliedWhenEmptyValueWithPresent ()
685
+ {
686
+ $ validation = $ this ->validator ->validate ([
687
+ 'must_present_field ' => '' ,
688
+ ], [
689
+ 'must_present_field ' => 'present|array ' ,
690
+ ]);
691
+
692
+ $ errors = $ validation ->errors ();
693
+
694
+ $ this ->assertEquals ($ errors ->count (), 1 );
695
+
696
+ $ this ->assertNull ($ errors ->first ('must_present_field:present ' ));
697
+ $ this ->assertNotNull ($ errors ->first ('must_present_field:array ' ));
698
+ }
699
+
684
700
public function testIgnoreOtherRulesWhenAttributeIsNotRequired ()
685
701
{
686
702
$ validation = $ this ->validator ->validate ([
You can’t perform that action at this time.
0 commit comments