ConsultValidator.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace App\Http\Validator;
  3. class ConsultValidator extends BaseValidator
  4. {
  5. // 当前模型所有验证规则
  6. public static $rules = [
  7. 'id' => 'required',
  8. 'realname' => 'required|max:20',
  9. 'mobile' => 'required|mobile|max:30',
  10. ];
  11. public static $msgs = [
  12. 'required' => ':attribute不能为空',
  13. 'string' => ':attribute必须是字符串',
  14. 'min' => ':attribute长度不能小于:min位',
  15. 'max' => ':attribute长度不能大于:max位',
  16. 'exists' => ':attribute不存在',
  17. 'rule' => ':attribute格式不正确',
  18. 'mobile' => ':attribute格式不正确',
  19. ];
  20. // 当前模型所有验证字段
  21. public static $fields = [
  22. 'id' => 'ID',
  23. 'realname' => '姓名',
  24. 'mobile' => '联系方式',
  25. ];
  26. // 当前模型所有验证场景
  27. public static $scenes = [
  28. 'submit'=> ['realname','mobile'],
  29. 'del'=> ['id'],
  30. ];
  31. /**
  32. * 验证
  33. * @param $request
  34. * @param string $scene
  35. * @return int|mixed
  36. */
  37. public static function check($request, $scene=''){
  38. $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
  39. return $validator->checkParams($request, $scene);
  40. }
  41. }