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.

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