File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ public function check($value)
23
23
24
24
$ anotherAttribute = $ this ->parameter ('field ' );
25
25
$ definedValues = $ this ->parameter ('values ' );
26
- $ anotherValue = $ this ->validation ->getValue ($ anotherAttribute );
26
+ $ anotherValue = $ this ->getAttribute () ->getValue ($ anotherAttribute );
27
27
28
28
$ validator = $ this ->validation ->getValidator ();
29
29
$ required_validator = $ validator ('required ' );
Original file line number Diff line number Diff line change @@ -842,4 +842,38 @@ public function testRequiredIfOnArrayAttribute()
842
842
$ this ->assertNull ($ errors ->first ('products.14.notes ' ));
843
843
}
844
844
845
+ public function testRequiredUnlessOnArrayAttribute ()
846
+ {
847
+ $ validation = $ this ->validator ->validate ([
848
+ 'products ' => [
849
+ // valid because has_notes is 1
850
+ '10 ' => [
851
+ 'quantity ' => 8 ,
852
+ 'has_notes ' => 1 ,
853
+ 'notes ' => ''
854
+ ],
855
+ // invalid because has_notes is not 1
856
+ '12 ' => [
857
+ 'quantity ' => 0 ,
858
+ 'has_notes ' => null ,
859
+ 'notes ' => ''
860
+ ],
861
+ // invalid because no has_notes
862
+ '14 ' => [
863
+ 'quantity ' => 0 ,
864
+ 'notes ' => ''
865
+ ],
866
+ ]
867
+ ], [
868
+ 'products.*.notes ' => 'required_unless:products.*.has_notes,1 ' ,
869
+ ]);
870
+
871
+ $ this ->assertFalse ($ validation ->passes ());
872
+
873
+ $ errors = $ validation ->errors ();
874
+ $ this ->assertNull ($ errors ->first ('products.10.notes ' ));
875
+ $ this ->assertNotNull ($ errors ->first ('products.12.notes ' ));
876
+ $ this ->assertNotNull ($ errors ->first ('products.14.notes ' ));
877
+ }
878
+
845
879
}
You can’t perform that action at this time.
0 commit comments