ActivityValidator.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Http\Validator;
  3. class ActivityValidator extends BaseValidator
  4. {
  5. // 当前模型所有验证规则
  6. public static $rules = [
  7. 'id' => 'required',
  8. 'coupon_give' => 'required|string|min:1|max:10',
  9. 'gd_name' => 'required|string|min:2|max:30',
  10. 'ws_name' => 'required|string|min:2|max:30',
  11. 'xy_content' => 'string|min:4|max:200',
  12. ];
  13. // 当前模型所有错误提示信息
  14. public static $msgs = [
  15. 'required' => ':attribute不能为空',
  16. 'string' => ':attribute必须是字符串',
  17. 'min' => ':attribute长度不能小于:min位',
  18. 'max' => ':attribute长度不能大于:max位',
  19. 'exists' => ':attribute不存在',
  20. 'rule' => ':attribute格式不正确',
  21. ];
  22. // 当前模型所有验证字段
  23. public static $fields = [
  24. 'id' => '活动ID',
  25. 'coupon' => '随喜券数',
  26. 'gd_name' => '功德主',
  27. 'ws_name' => '往生者',
  28. 'xy_content' => '心愿',
  29. ];
  30. // 当前模型所有验证场景
  31. public static $scenes = [
  32. 'info'=> ['id'],
  33. 'books'=> ['id','gd_name','ws_name','xy_content'],
  34. ];
  35. /**
  36. * 验证
  37. * @param $request
  38. * @param string $scene
  39. * @return int|mixed
  40. */
  41. public static function check($request, $scene=''){
  42. $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
  43. return $validator->checkParams($request, $scene);
  44. }
  45. }