LiveValidator.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Http\Validator;
  3. class LiveValidator extends BaseValidator
  4. {
  5. // 当前模型所有验证规则
  6. public static $rules = [
  7. 'id' => 'required',
  8. 'title' => 'required|max:200',
  9. 'description' => 'max:200',
  10. 'push_url' => 'required|max:200',
  11. 'play_url' => 'required:max:200',
  12. 'type' => 'required',
  13. ];
  14. // 当前模型所有错误提示信息
  15. public static $msgs = [
  16. 'required' => ':attribute不能为空',
  17. 'string' => ':attribute必须是字符串',
  18. 'min' => ':attribute长度不能小于:min位',
  19. 'max' => ':attribute长度不能大于:max位',
  20. 'exists' => ':attribute不存在',
  21. 'rule' => ':attribute格式不正确',
  22. ];
  23. // 当前模型所有验证字段
  24. public static $fields = [
  25. 'id' => 'ID',
  26. 'push_url' => '直播推流地址',
  27. 'play_url' => '直播播放地址',
  28. 'title' => '直播主题',
  29. 'description' => '直播内容',
  30. 'category' => '直播内容分类',
  31. 'type' => '直播类型',
  32. ];
  33. // 当前模型所有验证场景
  34. public static $scenes = [
  35. 'info'=> ['id'],
  36. 'create'=> ['description','push_url','play_url','category','type'],
  37. ];
  38. /**
  39. * 验证
  40. * @param $request
  41. * @param string $scene
  42. * @return int|mixed
  43. */
  44. public static function check($request, $scene=''){
  45. $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
  46. return $validator->checkParams($request, $scene);
  47. }
  48. }