@@ -302,11 +302,11 @@ class Validator implements ValidatorContract
302302 protected $ defaultNumericRules = ['Numeric ' , 'Integer ' , 'Decimal ' ];
303303
304304 /**
305- * The current placeholder for dots in rule keys .
305+ * The current random hash for the validator .
306306 *
307307 * @var string
308308 */
309- protected $ dotPlaceholder ;
309+ protected static $ placeholderHash ;
310310
311311 /**
312312 * The exception to throw upon failure.
@@ -335,7 +335,9 @@ class Validator implements ValidatorContract
335335 public function __construct (Translator $ translator , array $ data , array $ rules ,
336336 array $ messages = [], array $ attributes = [])
337337 {
338- $ this ->dotPlaceholder = Str::random ();
338+ if (! isset (static ::$ placeholderHash )) {
339+ static ::$ placeholderHash = Str::random ();
340+ }
339341
340342 $ this ->initialRules = $ rules ;
341343 $ this ->translator = $ translator ;
@@ -363,7 +365,7 @@ public function parseData(array $data)
363365
364366 $ key = str_replace (
365367 ['. ' , '* ' ],
366- [$ this -> dotPlaceholder , '__asterisk__ ' ],
368+ [' __dot__ ' . static :: $ placeholderHash , '__asterisk__ ' . static :: $ placeholderHash ],
367369 $ key
368370 );
369371
@@ -401,7 +403,7 @@ protected function replacePlaceholders($data)
401403 protected function replacePlaceholderInString (string $ value )
402404 {
403405 return str_replace (
404- [$ this -> dotPlaceholder , '__asterisk__ ' ],
406+ [' __dot__ ' . static :: $ placeholderHash , '__asterisk__ ' . static :: $ placeholderHash ],
405407 ['. ' , '* ' ],
406408 $ value
407409 );
@@ -720,7 +722,7 @@ protected function getPrimaryAttribute($attribute)
720722 protected function replaceDotInParameters (array $ parameters )
721723 {
722724 return array_map (function ($ field ) {
723- return str_replace ('\. ' , $ this -> dotPlaceholder , $ field );
725+ return str_replace ('\. ' , ' __dot__ ' . static :: $ placeholderHash , $ field );
724726 }, $ parameters );
725727 }
726728
@@ -846,11 +848,23 @@ protected function hasNotFailedPreviousRuleIfPresenceRule($rule, $attribute)
846848 */
847849 protected function validateUsingCustomRule ($ attribute , $ value , $ rule )
848850 {
849- $ attribute = $ this ->replacePlaceholderInString ($ attribute );
851+ $ originalAttribute = $ this ->replacePlaceholderInString ($ attribute );
852+
853+ $ attribute = match (true ) {
854+ $ rule instanceof Rules \File => $ attribute ,
855+ $ rule instanceof Rules \Password => $ attribute ,
856+ default => $ originalAttribute ,
857+ };
850858
851859 $ value = is_array ($ value ) ? $ this ->replacePlaceholders ($ value ) : $ value ;
852860
853861 if ($ rule instanceof ValidatorAwareRule) {
862+ if ($ attribute !== $ originalAttribute ) {
863+ $ this ->addCustomAttributes ([
864+ $ attribute => $ this ->customAttributes [$ originalAttribute ] ?? $ originalAttribute ,
865+ ]);
866+ }
867+
854868 $ rule ->setValidator ($ this );
855869 }
856870
@@ -863,14 +877,14 @@ protected function validateUsingCustomRule($attribute, $value, $rule)
863877 get_class ($ rule ->invokable ()) :
864878 get_class ($ rule );
865879
866- $ this ->failedRules [$ attribute ][$ ruleClass ] = [];
880+ $ this ->failedRules [$ originalAttribute ][$ ruleClass ] = [];
867881
868- $ messages = $ this ->getFromLocalArray ($ attribute , $ ruleClass ) ?? $ rule ->message ();
882+ $ messages = $ this ->getFromLocalArray ($ originalAttribute , $ ruleClass ) ?? $ rule ->message ();
869883
870884 $ messages = $ messages ? (array ) $ messages : [$ ruleClass ];
871885
872886 foreach ($ messages as $ key => $ message ) {
873- $ key = is_string ($ key ) ? $ key : $ attribute ;
887+ $ key = is_string ($ key ) ? $ key : $ originalAttribute ;
874888
875889 $ this ->messages ->add ($ key , $ this ->makeReplacements (
876890 $ message , $ key , $ ruleClass , []
@@ -1159,7 +1173,7 @@ public function getRulesWithoutPlaceholders()
11591173 {
11601174 return collect ($ this ->rules )
11611175 ->mapWithKeys (fn ($ value , $ key ) => [
1162- str_replace ($ this -> dotPlaceholder , '\\. ' , $ key ) => $ value ,
1176+ str_replace (' __dot__ ' . static :: $ placeholderHash , '\\. ' , $ key ) => $ value ,
11631177 ])
11641178 ->all ();
11651179 }
@@ -1173,7 +1187,7 @@ public function getRulesWithoutPlaceholders()
11731187 public function setRules (array $ rules )
11741188 {
11751189 $ rules = collect ($ rules )->mapWithKeys (function ($ value , $ key ) {
1176- return [str_replace ('\. ' , $ this -> dotPlaceholder , $ key ) => $ value ];
1190+ return [str_replace ('\. ' , ' __dot__ ' . static :: $ placeholderHash , $ key ) => $ value ];
11771191 })->toArray ();
11781192
11791193 $ this ->initialRules = $ rules ;
0 commit comments