You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.4 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Requests;
  3. class ArticleRequest extends BaseRequest
  4. {
  5. //总的验证规则
  6. protected $rules = [
  7. 'id' => 'required|integer',
  8. 'typeid' => 'required|integer',
  9. 'tuijian' => 'integer',
  10. 'click' => 'required|integer',
  11. 'title' => 'required|max:150',
  12. 'writer' => 'max:20',
  13. 'source' => 'max:30',
  14. 'litpic' => 'max:100',
  15. 'pubdate' => 'integer',
  16. 'add_time' => 'required|integer',
  17. 'keywords' => 'max:60',
  18. 'seotitle' => 'max:150',
  19. 'description' => 'max:250',
  20. 'ischeck' => 'between:0,2',
  21. 'user_id' => 'integer',
  22. ];
  23. //总的自定义错误信息
  24. protected $messages = [
  25. 'id.required' => 'ID必填',
  26. 'id.integer' => 'ID必须为数字',
  27. 'typeid.required' => '栏目ID必填',
  28. 'typeid.integer' => '栏目ID必须为数字',
  29. 'tuijian.integer' => '推荐等级必须是数字',
  30. 'click.required' => '点击量必填',
  31. 'click.integer' => '点击量必须为数字',
  32. 'title.max' => '标题不能大于150个字符',
  33. 'title.required' => '必须填写标题',
  34. 'writer.max' => '作者不能超过20个字符',
  35. 'source.max' => '来源不能超过30个字符',
  36. 'litpic.max' => '缩略图不能超过100个字符',
  37. 'pubdate.integer' => '更新时间格式不正确',
  38. 'add_time.required' => '添加时间必填',
  39. 'add_time.integer' => '添加时间必须是数字',
  40. 'keywords.max' => '关键词不能超过60个字符',
  41. 'seotitle.max' => 'seo标题不能超过150个字符',
  42. 'description.max' => '描述不能超过250个字符',
  43. 'ischeck.between' => '审核状态:0审核,1未审核',
  44. 'user_id.integer' => '发布者ID必须是数字',
  45. ];
  46. //场景验证规则
  47. protected $scene = [
  48. 'add' => ['typeid', 'title', 'tuijian', 'click', 'writer', 'source', 'litpic', 'pubdate', 'addtime', 'keywords', 'seotitle', 'description', 'ischeck', 'user_id'],
  49. 'edit' => ['typeid', 'title', 'tuijian', 'click', 'writer', 'source', 'litpic', 'pubdate', 'addtime', 'keywords', 'seotitle', 'description', 'ischeck', 'user_id'],
  50. 'del' => ['id'],
  51. ];
  52. /**
  53. * Determine if the user is authorized to make this request.
  54. *
  55. * @return bool
  56. */
  57. public function authorize()
  58. {
  59. return true; //修改为true
  60. }
  61. /**
  62. * Get the validation rules that apply to the request.
  63. *
  64. * @return array
  65. */
  66. public function rules()
  67. {
  68. return $this->rules;
  69. }
  70. /**
  71. * 获取被定义验证规则的错误消息.
  72. *
  73. * @return array
  74. */
  75. public function messages()
  76. {
  77. return $this->messages;
  78. }
  79. //获取场景验证规则
  80. public function getSceneRules($name, $fields = null)
  81. {
  82. $res = array();
  83. if(!isset($this->scene[$name]))
  84. {
  85. return false;
  86. }
  87. $scene = $this->scene[$name];
  88. if($fields != null && is_array($fields))
  89. {
  90. $scene = $fields;
  91. }
  92. foreach($scene as $k=>$v)
  93. {
  94. if(isset($this->rules[$v])){$res[$v] = $this->rules[$v];}
  95. }
  96. return $res;
  97. }
  98. //获取场景验证规则自定义错误信息
  99. public function getSceneRulesMessages()
  100. {
  101. return $this->messages;
  102. }
  103. }