File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -53,9 +53,12 @@ public function validate()
5353 'city ' => 'required ' ,
5454 'zip ' => 'required ' ,
5555 'countryId ' => 'required ' ,
56- 'stateId ' => 'required ' ,
5756 ];
5857
58+ if ($ this ->countryId && Country::find ($ this ->countryId )?->states()->exists ()) {
59+ $ rules ['stateId ' ] = 'required ' ;
60+ }
61+
5962 Validator::validate ($ this ->config , $ rules , [
6063 'addressLine1 ' => __ ("The address field is required " )
6164 ]);
@@ -89,9 +92,13 @@ public function validateFromPost(?User $user = null)
8992 $ prefix .'city ' => 'required ' ,
9093 $ prefix .'zip ' => 'required ' ,
9194 $ prefix .'country_id ' => 'required ' ,
92- $ prefix .'state_id ' => 'required ' ,
9395 ];
9496
97+ $ countryId = post ($ prefix .'country_id ' );
98+ if ($ countryId && Country::find ($ countryId )?->states()->exists ()) {
99+ $ rules [$ prefix .'state_id ' ] = 'required ' ;
100+ }
101+
95102 Validator::validate ($ data , $ rules , [
96103 $ prefix .'address_line1 ' => __ ("The address field is required " )
97104 ]);
You can’t perform that action at this time.
0 commit comments