File tree Expand file tree Collapse file tree 2 files changed +46
-4
lines changed
src/Illuminate/Validation/Rules Expand file tree Collapse file tree 2 files changed +46
-4
lines changed Original file line number Diff line number Diff line change 3
3
namespace Illuminate \Validation \Rules ;
4
4
5
5
use Illuminate \Contracts \Validation \Rule ;
6
+ use Illuminate \Contracts \Validation \ValidatorAwareRule ;
6
7
use Illuminate \Support \Facades \Gate ;
7
8
8
- class Can implements Rule
9
+ class Can implements Rule, ValidatorAwareRule
9
10
{
10
11
/**
11
12
* The ability to check.
@@ -21,6 +22,13 @@ class Can implements Rule
21
22
*/
22
23
protected $ arguments ;
23
24
25
+ /**
26
+ * The current validator instance.
27
+ *
28
+ * @var \Illuminate\Validation\Validator
29
+ */
30
+ protected $ validator ;
31
+
24
32
/**
25
33
* Constructor.
26
34
*
@@ -56,10 +64,23 @@ public function passes($attribute, $value)
56
64
*/
57
65
public function message ()
58
66
{
59
- $ message = trans ('validation.can ' );
67
+ $ message = $ this -> validator -> getTranslator ()-> get ('validation.can ' );
60
68
61
69
return $ message === 'validation.can '
62
70
? ['The :attribute field contains an unauthorized value. ' ]
63
71
: $ message ;
64
72
}
73
+
74
+ /**
75
+ * Set the current validator.
76
+ *
77
+ * @param \Illuminate\Validation\Validator $validator
78
+ * @return $this
79
+ */
80
+ public function setValidator ($ validator )
81
+ {
82
+ $ this ->validator = $ validator ;
83
+
84
+ return $ this ;
85
+ }
65
86
}
Original file line number Diff line number Diff line change 3
3
namespace Illuminate \Validation \Rules ;
4
4
5
5
use Illuminate \Contracts \Validation \Rule ;
6
+ use Illuminate \Contracts \Validation \ValidatorAwareRule ;
6
7
use TypeError ;
7
8
8
- class Enum implements Rule
9
+ class Enum implements Rule, ValidatorAwareRule
9
10
{
10
11
/**
11
12
* The type of the enum.
@@ -14,6 +15,13 @@ class Enum implements Rule
14
15
*/
15
16
protected $ type ;
16
17
18
+ /**
19
+ * The current validator instance.
20
+ *
21
+ * @var \Illuminate\Validation\Validator
22
+ */
23
+ protected $ validator ;
24
+
17
25
/**
18
26
* Create a new rule instance.
19
27
*
@@ -56,10 +64,23 @@ public function passes($attribute, $value)
56
64
*/
57
65
public function message ()
58
66
{
59
- $ message = trans ('validation.enum ' );
67
+ $ message = $ this -> validator -> getTranslator ()-> get ('validation.enum ' );
60
68
61
69
return $ message === 'validation.enum '
62
70
? ['The selected :attribute is invalid. ' ]
63
71
: $ message ;
64
72
}
73
+
74
+ /**
75
+ * Set the current validator.
76
+ *
77
+ * @param \Illuminate\Validation\Validator $validator
78
+ * @return $this
79
+ */
80
+ public function setValidator ($ validator )
81
+ {
82
+ $ this ->validator = $ validator ;
83
+
84
+ return $ this ;
85
+ }
65
86
}
You can’t perform that action at this time.
0 commit comments