MemberValidator.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Http\Validator;
  3. class MemberValidator extends BaseValidator
  4. {
  5. // 当前模型所有验证规则
  6. public static $rules = [
  7. 'id' => 'required',
  8. 'mobile'=> 'required|mobile',
  9. 'avatar'=> 'required|max:200',
  10. 'nickname' => 'required|min:2|max:30',
  11. 'password' => 'required|min:4|max:30',
  12. 'safe_password' => 'required|min:6|max:30',
  13. 'shop_code' => 'required|min:2|max:20',
  14. 'invite_code' => 'required|min:2|max:20',
  15. ];
  16. // 当前模型所有错误提示信息
  17. public static $msgs = [
  18. 'required' => ':attribute不能为空',
  19. 'string' => ':attribute必须是字符串',
  20. 'min' => ':attribute长度不能小于:min位',
  21. 'max' => ':attribute长度不能大于:max位',
  22. 'exists' => ':attribute不存在',
  23. 'rule' => ':attribute格式不正确',
  24. ];
  25. // 当前模型所有验证字段
  26. public static $fields = [
  27. 'id' => 'ID',
  28. 'nickname' => '昵称',
  29. 'avatar' => '头像',
  30. 'mobile' => '手机号',
  31. 'shop_code' => '店铺编号',
  32. 'invite_code' => '邀请码',
  33. 'password' => '登录密码',
  34. 'safe_password' => '安全密码',
  35. ];
  36. // 当前模型所有验证场景
  37. public static $scenes = [
  38. 'info'=> ['id'],
  39. 'register'=> ['mobile','password','safe_password','invite_code'],
  40. 'login'=> ['mobile','password','shop_code'],
  41. 'save'=> ['nickname','avatar','password','safe_password'],
  42. 'password'=> ['password'],
  43. ];
  44. /**
  45. * 验证
  46. * @param $request
  47. * @param string $scene
  48. * @return int|mixed
  49. */
  50. public static function check($request, $scene=''){
  51. $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
  52. return $validator->checkParams($request, $scene);
  53. }
  54. }