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.

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