WorkValidator.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Http\Validator;
  3. class WorkValidator extends BaseValidator
  4. {
  5. // 当前模型所有验证规则
  6. public static $rules = [
  7. 'id' => 'required',
  8. 'realname' => 'required|string|min:1|max:20',
  9. 'phone' => 'required|string|min:2|max:20',
  10. ];
  11. // 当前模型所有错误提示信息
  12. public static $msgs = [
  13. 'required' => ':attribute不能为空',
  14. 'string' => ':attribute必须是字符串',
  15. 'min' => ':attribute长度不能小于:min位',
  16. 'max' => ':attribute长度不能大于:max位',
  17. 'exists' => ':attribute不存在',
  18. 'rule' => ':attribute格式不正确',
  19. ];
  20. // 当前模型所有验证字段
  21. public static $fields = [
  22. 'id' => 'ID',
  23. 'realname' => '姓名',
  24. 'phone' => '联系电话',
  25. ];
  26. // 当前模型所有验证场景
  27. public static $scenes = [
  28. 'info'=> ['id'],
  29. 'books'=> ['id','realname','phone'],
  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. }