laravel 自定义验证 Validator::extend _fei


laravel 自定义验证 Validator::extend

 1 $messages = [
 2     'name.integer' => '名字不能为整型', 
 3     'name.max' => '长度不能超过5',
 4 ];
 5 
 6 public static $rules=[
 7     'name' => 'required|integer|max:5|foo_fei', //foo_fei 自定义验证
 8     'score' => 'required|integer',
 9 ];
10 
11 Validator::extend('foo_fei', function ($attribute, $value, $parameters) { //exit('进来了');
12     return $value=='foo';
13     //这里的错误消息在 resources/lang/en/validation.php 
14     // 'custom'               => [
15     //     'attribute-name' => [
16     //         'rule-name' => 'custom-message',
17     //     ],
18     //     'name'=> [
19     //         'foo_fei'=>'你是傻逼'
20     //     ],
21     // ],
22 });
23 
24  $validatedData = Validator::make($data,Student::$rules,$messages);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM