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.

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