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.

100 lines
2.7 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
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 RegionRequest extends BaseRequest
  4. {
  5. //总的验证规则
  6. protected $rules = [
  7. 'id' => 'required|integer',
  8. 'name' => 'required|max:64',
  9. 'parent_id' => 'integer',
  10. 'type' => 'integer|between:0,3',
  11. 'sort_name' => 'max:50',
  12. 'is_oversea' => 'integer|between:0,1',
  13. 'area_code' => 'max:10',
  14. 'status' => 'integer|between:0,1',
  15. ];
  16. //总的自定义错误信息
  17. protected $messages = [
  18. 'id.required' => 'ID必填',
  19. 'id.integer' => 'ID必须为数字',
  20. 'name.required' => '名称必填',
  21. 'name.max' => '名称不能超过60个字符',
  22. 'parent_id.integer' => '父级id必须为数字',
  23. 'type.integer' => '层级必须是数字',
  24. 'type.between' => '层级,0国家,1省,2市,3区',
  25. 'sort_name.max' => '拼音或英文简写不能超过50个字符',
  26. 'is_oversea.integer' => '类型必须是数字',
  27. 'is_oversea.between' => '0国内地址,1国外地址',
  28. 'area_code.max' => '电话区号不能超过10个字符',
  29. 'status.integer' => '状态必须是数字',
  30. 'status.between' => '状态 0隐藏 1显示',
  31. ];
  32. //场景验证规则
  33. protected $scene = [
  34. 'add' => ['name', 'parent_id', 'type', 'sort_name', 'is_oversea', 'area_code', 'status'],
  35. 'edit' => ['name', 'parent_id', 'type', 'sort_name', 'is_oversea', 'area_code', 'status'],
  36. 'del' => ['id'],
  37. ];
  38. /**
  39. * Determine if the user is authorized to make this request.
  40. *
  41. * @return bool
  42. */
  43. public function authorize()
  44. {
  45. return true; //修改为true
  46. }
  47. /**
  48. * Get the validation rules that apply to the request.
  49. *
  50. * @return array
  51. */
  52. public function rules()
  53. {
  54. return $this->rules;
  55. }
  56. /**
  57. * 获取被定义验证规则的错误消息.
  58. *
  59. * @return array
  60. */
  61. public function messages()
  62. {
  63. return $this->messages;
  64. }
  65. //获取场景验证规则
  66. public function getSceneRules($name, $fields = null)
  67. {
  68. $res = array();
  69. if(!isset($this->scene[$name]))
  70. {
  71. return false;
  72. }
  73. $scene = $this->scene[$name];
  74. if($fields != null && is_array($fields))
  75. {
  76. $scene = $fields;
  77. }
  78. foreach($scene as $k=>$v)
  79. {
  80. if(isset($this->rules[$v])){$res[$v] = $this->rules[$v];}
  81. }
  82. return $res;
  83. }
  84. //获取场景验证规则自定义错误信息
  85. public function getSceneRulesMessages()
  86. {
  87. return $this->messages;
  88. }
  89. }