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.

104 lines
2.8 KiB

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