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.

91 lines
2.1 KiB

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