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
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
6 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' => 'required|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.required' => '发布者ID必填',
  24. 'user_id.integer' => '发布者ID必须是数字',
  25. 'mobile.max' => '手机号码不能超过20个字符',
  26. 'type.max' => '意见反馈类型不能超过20个字符',
  27. ];
  28. //场景验证规则
  29. protected $scene = [
  30. 'add' => ['content', 'title', 'mobile', 'type'],
  31. 'edit' => ['content', 'title', 'mobile', 'type'],
  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. }