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.

103 lines
2.8 KiB

7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Requests;
  3. class SlideRequest extends BaseRequest
  4. {
  5. //总的验证规则
  6. protected $rules = [
  7. 'id' => 'required|integer',
  8. 'title' => 'required|max:150',
  9. 'url' => 'max:100',
  10. 'target' => 'integer|between:0,5',
  11. 'group_id' => 'integer',
  12. 'listorder' => 'integer',
  13. 'pic' => 'required|max:100',
  14. 'is_show' => 'integer|between:0,2',
  15. 'type' => 'integer|between:0,5'
  16. ];
  17. //总的自定义错误信息
  18. protected $messages = [
  19. 'id.required' => 'ID必填',
  20. 'id.integer' => 'ID必须为数字',
  21. 'title.required' => '标题必填',
  22. 'title.max' => '标题不能超过150个字符',
  23. 'url.max' => 'url不能超过100个字符',
  24. 'target.integer' => 'target必须为数字',
  25. 'target.between' => '跳转方式,0_blank,1_self,2_parent,3_top,4framename',
  26. 'group_id.integer' => '分组ID必须是数字',
  27. 'listorder.integer' => '排序必须是数字',
  28. 'pic.required' => '图片',
  29. 'pic.max' => '图片地址不能超过100个字符',
  30. 'is_show.integer' => '是否显示必须为数字',
  31. 'is_show.between' => '是否显示,默认0显示',
  32. 'type.integer' => '类型必须为数字',
  33. 'type.between' => '类型0pc,1weixin,2app,3wap',
  34. ];
  35. //场景验证规则
  36. protected $scene = [
  37. 'add' => ['title', 'url', 'target', 'group_id', 'listorder', 'pic', 'is_show', 'type'],
  38. 'edit' => ['title', 'url', 'target', 'group_id', 'listorder', 'pic', 'is_show', 'type'],
  39. 'del' => ['id'],
  40. ];
  41. /**
  42. * Determine if the user is authorized to make this request.
  43. *
  44. * @return bool
  45. */
  46. public function authorize()
  47. {
  48. return true; //修改为true
  49. }
  50. /**
  51. * Get the validation rules that apply to the request.
  52. *
  53. * @return array
  54. */
  55. public function rules()
  56. {
  57. return $this->rules;
  58. }
  59. /**
  60. * 获取被定义验证规则的错误消息.
  61. *
  62. * @return array
  63. */
  64. public function messages()
  65. {
  66. return $this->messages;
  67. }
  68. //获取场景验证规则
  69. public function getSceneRules($name, $fields = null)
  70. {
  71. $res = array();
  72. if(!isset($this->scene[$name]))
  73. {
  74. return false;
  75. }
  76. $scene = $this->scene[$name];
  77. if($fields != null && is_array($fields))
  78. {
  79. $scene = $fields;
  80. }
  81. foreach($scene as $k=>$v)
  82. {
  83. if(isset($this->rules[$v])){$res[$v] = $this->rules[$v];}
  84. }
  85. return $res;
  86. }
  87. //获取场景验证规则自定义错误信息
  88. public function getSceneRulesMessages()
  89. {
  90. return $this->messages;
  91. }
  92. }