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.

96 lines
2.4 KiB

7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Requests;
  3. class GoodsSearchwordRequest extends BaseRequest
  4. {
  5. //总的验证规则
  6. protected $rules = [
  7. 'id' => 'required|integer',
  8. 'name' => 'required|max:60',
  9. 'status' => 'integer|between:0,5',
  10. 'add_time' => 'required|integer',
  11. 'listorder' => 'integer|between:1,9999',
  12. 'click' => 'integer',
  13. ];
  14. //总的自定义错误信息
  15. protected $messages = [
  16. 'id.required' => 'ID必填',
  17. 'id.integer' => 'ID必须为数字',
  18. 'name.required' => '标题必填',
  19. 'name.max' => '标题不能超过60个字符',
  20. 'status.integer' => '状态必须是数字',
  21. 'status.between' => '状态 0显示',
  22. 'add_time.required' => '添加时间必填',
  23. 'add_time.integer' => '添加时间必须是数字',
  24. 'listorder.integer' => '排序必须是数字',
  25. 'listorder.between' => '排序只能1-9999',
  26. 'click.integer' => '点击必须为数字',
  27. ];
  28. //场景验证规则
  29. protected $scene = [
  30. 'add' => ['name', 'status', 'add_time', 'listorder', 'click'],
  31. 'edit' => ['name', 'status', 'add_time', 'listorder', 'click'],
  32. 'del' => ['id'],
  33. ];
  34. /**
  35. * Determine if the user is authorized to make this request.
  36. *
  37. * @return bool
  38. */
  39. public function authorize()
  40. {
  41. return true; //修改为true
  42. }
  43. /**
  44. * Get the validation rules that apply to the request.
  45. *
  46. * @return array
  47. */
  48. public function rules()
  49. {
  50. return $this->rules;
  51. }
  52. /**
  53. * 获取被定义验证规则的错误消息.
  54. *
  55. * @return array
  56. */
  57. public function messages()
  58. {
  59. return $this->messages;
  60. }
  61. //获取场景验证规则
  62. public function getSceneRules($name, $fields = null)
  63. {
  64. $res = array();
  65. if(!isset($this->scene[$name]))
  66. {
  67. return false;
  68. }
  69. $scene = $this->scene[$name];
  70. if($fields != null && is_array($fields))
  71. {
  72. $scene = $fields;
  73. }
  74. foreach($scene as $k=>$v)
  75. {
  76. if(isset($this->rules[$v])){$res[$v] = $this->rules[$v];}
  77. }
  78. return $res;
  79. }
  80. //获取场景验证规则自定义错误信息
  81. public function getSceneRulesMessages()
  82. {
  83. return $this->messages;
  84. }
  85. }