File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 11
11
12
12
use App \Events \TestEvent ;
13
13
use App \Http \Repository \NewBusRepository ;
14
+ use App \Rules \Uppercase ;
14
15
use App \Tasks \TestTask ;
15
16
use Hhxsv5 \LaravelS \Swoole \Task \Event ;
16
17
use Hhxsv5 \LaravelS \Swoole \Task \Task ;
@@ -125,12 +126,15 @@ public function jwt(Request $request)
125
126
'title ' => [
126
127
'required ' ,
127
128
'max:255 ' ,
128
- function ($ attribute , $ value , $ fail ) {
129
+ function ($ attribute , $ value , $ fail ) {
129
130
if ($ value === 'foo ' ) {
130
131
$ fail ($ attribute .' is invalid. ' );
131
132
}
132
133
},
133
134
],
135
+ 'upper ' => [
136
+ 'required ' , 'string ' , new Uppercase ()
137
+ ]
134
138
];
135
139
136
140
$ messages = [
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Rules ;
4
+
5
+ use Illuminate \Contracts \Validation \Rule ;
6
+
7
+ class Uppercase implements Rule
8
+ {
9
+ /**
10
+ * 判断验证规则是否通过。
11
+ *
12
+ * @param string $attribute
13
+ * @param mixed $value
14
+ * @return bool
15
+ */
16
+ public function passes ($ attribute , $ value )
17
+ {
18
+ return strtoupper ($ value ) === $ value ;
19
+ }
20
+
21
+ /**
22
+ * 获取验证错误消息。
23
+ *
24
+ * @return string
25
+ */
26
+ public function message ()
27
+ {
28
+ return ':attribute 必须是大写字母 ' ;
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments