MemberValidator.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Http\Validator;
  3. class MemberValidator extends BaseValidator
  4. {
  5. // 当前模型所有验证规则
  6. public static $rules = [
  7. 'id' => 'required',
  8. 'username' => 'required|username|min:2|max:20',
  9. 'new_username' => 'required|username|min:2|max:20',
  10. 'password' => 'required|max:30',
  11. 'code' => 'required',
  12. 'mobile'=> 'required|mobile',
  13. 'email'=> 'required|email',
  14. 'idcard'=> 'required|idcard',
  15. 'realname'=> 'required|max:20',
  16. 'idcard_front_img'=> 'required|max:200',
  17. 'idcard_back_img'=> 'required|max:200',
  18. ];
  19. // 当前模型所有错误提示信息
  20. public static $msgs = [
  21. 'required' => ':attribute不能为空',
  22. 'string' => ':attribute必须是字符串',
  23. 'min' => ':attribute长度不能小于:min位',
  24. 'max' => ':attribute长度不能大于:max位',
  25. 'exists' => ':attribute不存在',
  26. 'rule' => ':attribute格式不正确',
  27. 'mobile' => ':attribute格式不正确',
  28. 'email' => ':attribute格式不正确',
  29. 'username' => ':attribute格式不正确',
  30. 'idcard' => ':attribute格式不正确',
  31. ];
  32. // 当前模型所有验证字段
  33. public static $fields = [
  34. 'id' => 'ID',
  35. 'password' => '登录密码',
  36. 'username' => '账号',
  37. 'new_username' => '新账号',
  38. 'code' => '验证码',
  39. 'mobile' => '手机号码',
  40. 'email' => '邮箱',
  41. 'realname' => '姓名',
  42. 'idcard' => '身份证号码',
  43. 'idcard_front_img' => '身份证正面',
  44. 'idcard_back_img' => '身份证反面',
  45. ];
  46. // 当前模型所有验证场景
  47. public static $scenes = [
  48. 'info'=> ['id'],
  49. 'register'=> ['username','password','code'],
  50. 'modify'=> ['username','new_username','password','code'],
  51. 'auth'=> ['realname','idcard','idcard_front_img','idcard_back_img'],
  52. 'login'=> ['username','password'],
  53. 'forget'=> ['username','code'],
  54. 'save'=> ['username','realname','gender'],
  55. 'mobile'=> ['mobile'],
  56. 'email'=> ['email'],
  57. ];
  58. /**
  59. * 验证
  60. * @param $request
  61. * @param string $scene
  62. * @return int|mixed
  63. */
  64. public static function check($request, $scene=''){
  65. $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
  66. return $validator->checkParams($request, $scene);
  67. }
  68. }