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.

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