@@ -25,28 +25,31 @@ function rules($rules, array $messages = [], array $customAttributes = []): Clos
25
25
$ rules = [$ rules ];
26
26
}
27
27
28
- return function (callable $ fail , $ value , $ model , Context $ context , Field $ field ) use ($ rules , $ messages , $ customAttributes ) {
28
+ return function (callable $ fail , $ value , Model $ model , Context $ context , Field $ field ) use (
29
+ $ rules ,
30
+ $ messages ,
31
+ $ customAttributes
32
+ ) {
29
33
$ key = $ field ->getName ();
30
- $ validationRules = [$ key => []];
31
- $ validationMessages = [$ key => []];
32
34
33
- foreach ($ rules as $ k => $ v ) {
34
- if (! is_numeric ($ k )) {
35
- $ validationRules [$ key .'. ' .$ k ] = $ v ;
36
- } else {
37
- $ validationRules [$ key ][] = $ v ;
38
- }
39
- }
35
+ $ validatorRules = [$ key => []];
36
+
37
+ foreach ($ rules as $ k => $ rule ) {
38
+ $ rule = str_replace ('{id} ' , $ model ->getKey (), $ rule );
40
39
41
- foreach ($ messages as $ k => $ v ) {
42
40
if (! is_numeric ($ k )) {
43
- $ validationMessages [$ key .'. ' .$ k ] = $ v ;
41
+ $ validatorRules [$ key .'. ' .$ k ] = $ rule ;
44
42
} else {
45
- $ validationMessages [$ key ][] = $ v ;
43
+ $ validatorRules [$ key ][] = $ rule ;
46
44
}
47
45
}
48
46
49
- $ validation = Validator::make ($ value !== null ? [$ key => $ value ] : [], $ validationRules , $ validationMessages , $ customAttributes );
47
+ $ validation = Validator::make (
48
+ $ value !== null ? [$ key => $ value ] : [],
49
+ $ validatorRules ,
50
+ $ messages ,
51
+ $ customAttributes
52
+ );
50
53
51
54
if ($ validation ->fails ()) {
52
55
foreach ($ validation ->errors ()->all () as $ message ) {
0 commit comments