@@ -287,8 +287,6 @@ public function passes()
287
287
foreach ($ this ->rules as $ attribute => $ rules ) {
288
288
$ attribute = str_replace ('\. ' , '-> ' , $ attribute );
289
289
290
- // If this attribute is a nested rule, its parent might have already
291
- // been excluded. If so, we have to remove the attribute.
292
290
if ($ this ->shouldBeExcluded ($ attribute )) {
293
291
$ this ->removeAttribute ($ attribute );
294
292
@@ -320,21 +318,27 @@ public function passes()
320
318
return $ this ->messages ->isEmpty ();
321
319
}
322
320
321
+ /**
322
+ * Determine if the data fails the validation rules.
323
+ *
324
+ * @return bool
325
+ */
326
+ public function fails ()
327
+ {
328
+ return ! $ this ->passes ();
329
+ }
330
+
323
331
/**
324
332
* Determine if the attribute should be excluded.
325
333
*
326
334
* @param string $attribute
327
- *
328
335
* @return bool
329
336
*/
330
337
protected function shouldBeExcluded ($ attribute )
331
338
{
332
339
foreach ($ this ->excludeAttributes as $ excludeAttribute ) {
333
- if ($ attribute === $ excludeAttribute ) {
334
- return true ;
335
- }
336
-
337
- if (Str::startsWith ($ attribute , $ excludeAttribute .'. ' )) {
340
+ if ($ attribute === $ excludeAttribute ||
341
+ Str::startsWith ($ attribute , $ excludeAttribute .'. ' )) {
338
342
return true ;
339
343
}
340
344
}
@@ -354,16 +358,6 @@ protected function removeAttribute($attribute)
354
358
unset($ this ->data [$ attribute ], $ this ->rules [$ attribute ]);
355
359
}
356
360
357
- /**
358
- * Determine if the data fails the validation rules.
359
- *
360
- * @return bool
361
- */
362
- public function fails ()
363
- {
364
- return ! $ this ->passes ();
365
- }
366
-
367
361
/**
368
362
* Run the validator's rules against its data.
369
363
*
@@ -688,9 +682,7 @@ public function addFailure($attribute, $rule, $parameters = [])
688
682
}
689
683
690
684
if (in_array ($ rule , $ this ->excludeRules )) {
691
- $ this ->excludeAttributes [] = $ attribute ;
692
-
693
- return ;
685
+ return $ this ->excludeAttribute ($ attribute );
694
686
}
695
687
696
688
$ this ->messages ->add ($ attribute , $ this ->makeReplacements (
@@ -700,6 +692,19 @@ public function addFailure($attribute, $rule, $parameters = [])
700
692
$ this ->failedRules [$ attribute ][$ rule ] = $ parameters ;
701
693
}
702
694
695
+ /**
696
+ * Add the given attribute to the list of excluded attributes.
697
+ *
698
+ * @param string $attribute
699
+ * @return void
700
+ */
701
+ protected function excludeAttribute (string $ attribute )
702
+ {
703
+ $ this ->excludeAttributes [] = $ attribute ;
704
+
705
+ $ this ->excludeAttributes = array_unique ($ this ->excludeAttributes );
706
+ }
707
+
703
708
/**
704
709
* Returns the data which was valid.
705
710
*
0 commit comments