| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace App\Http\Validator;
- class MemberValidator extends BaseValidator
- {
- // 当前模型所有验证规则
- public static $rules = [
- 'id' => 'required',
- 'mobile'=> 'required|mobile',
- 'avatar'=> 'required|max:200',
- 'nickname' => 'required|min:2|max:30',
- 'password' => 'required|min:4|max:30',
- 'safe_password' => 'required|min:6|max:30',
- 'shop_code' => 'required|min:2|max:20',
- 'invite_code' => 'required|min:2|max:20',
- ];
- // 当前模型所有错误提示信息
- public static $msgs = [
- 'required' => ':attribute不能为空',
- 'string' => ':attribute必须是字符串',
- 'min' => ':attribute长度不能小于:min位',
- 'max' => ':attribute长度不能大于:max位',
- 'exists' => ':attribute不存在',
- 'rule' => ':attribute格式不正确',
- ];
- // 当前模型所有验证字段
- public static $fields = [
- 'id' => 'ID',
- 'nickname' => '昵称',
- 'avatar' => '头像',
- 'mobile' => '手机号',
- 'shop_code' => '店铺编号',
- 'invite_code' => '邀请码',
- 'password' => '登录密码',
- 'safe_password' => '安全密码',
- ];
- // 当前模型所有验证场景
- public static $scenes = [
- 'info'=> ['id'],
- 'register'=> ['mobile','password','safe_password','invite_code'],
- 'login'=> ['mobile','password','shop_code'],
- 'save'=> ['nickname','avatar','password','safe_password'],
- 'password'=> ['password'],
- ];
- /**
- * 验证
- * @param $request
- * @param string $scene
- * @return int|mixed
- */
- public static function check($request, $scene=''){
- $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
- return $validator->checkParams($request, $scene);
- }
- }
|