Request.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace App\Http\Requests;
  3. use Illuminate\Contracts\Validation\Validator;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. use Illuminate\Http\Exceptions\HttpResponseException;
  6. abstract class Request extends FormRequest
  7. {
  8. public function authorize()
  9. {
  10. return true;
  11. }
  12. public function failedValidation(Validator $validator)
  13. {
  14. throw (new HttpResponseException(response()->json([
  15. 'code' => -1,
  16. 'msg' => '请求错误',
  17. 'data' => $validator->errors()->first(),
  18. ], 200)));
  19. }
  20. public function messages()
  21. {
  22. return [
  23. 'required' => '缺少参数:attribute',
  24. 'integer' => ':attribute 必须是整数类型',
  25. 'date' => ':attribute 必须是日期格式',
  26. 'max' => [
  27. 'numeric' => ':attribute不能超过 :max.',
  28. 'file' => '文件:attribute大小不能超过 :max kilobytes.',
  29. 'string' => '字符:attribute 不能超过 :max 长度.',
  30. 'array' => '数组:attribute 不能超过 :max 长度.',
  31. ],
  32. 'accepted' => 'The :attribute must be accepted.',
  33. 'active_url' => ':attribute 是个无效链接.',
  34. 'after' => 'The :attribute must be a date after :date.',
  35. 'after_or_equal' => 'The :attribute must be a date after or equal to :date.',
  36. 'alpha' => 'The :attribute may only contain letters.',
  37. 'alpha_dash' => 'The :attribute may only contain letters, numbers, dashes and underscores.',
  38. 'alpha_num' => 'The :attribute may only contain letters and numbers.',
  39. 'array' => 'The :attribute must be an array.',
  40. 'before' => 'The :attribute must be a date before :date.',
  41. 'before_or_equal' => 'The :attribute must be a date before or equal to :date.',
  42. 'between' => 'The :attribute 必须处于 :min 和 :max 之间',
  43. 'boolean' => 'The :attribute field must be true or false.',
  44. 'confirmed' => 'The :attribute confirmation does not match.',
  45. 'date_equals' => 'The :attribute must be a date equal to :date.',
  46. 'date_format' => 'The :attribute does not match the format :format.',
  47. 'different' => 'The :attribute and :other must be different.',
  48. 'digits' => 'The :attribute must be :digits digits.',
  49. 'digits_between' => 'The :attribute must be between :min and :max digits.',
  50. 'dimensions' => 'The :attribute has invalid image dimensions.',
  51. 'distinct' => 'The :attribute field has a duplicate value.',
  52. 'email' => 'The :attribute must be a valid email address.',
  53. 'ends_with' => 'The :attribute must end with one of the following: :values',
  54. 'exists' => ':attribute 不存在.',
  55. 'file' => 'The :attribute must be a file.',
  56. 'filled' => 'The :attribute field must have a value.',
  57. 'gt' => [
  58. 'numeric' => 'The :attribute must be greater than :value.',
  59. 'file' => 'The :attribute must be greater than :value kilobytes.',
  60. 'string' => 'The :attribute must be greater than :value characters.',
  61. 'array' => 'The :attribute must have more than :value items.',
  62. ],
  63. 'gte' => [
  64. 'numeric' => 'The :attribute must be greater than or equal :value.',
  65. 'file' => 'The :attribute must be greater than or equal :value kilobytes.',
  66. 'string' => 'The :attribute must be greater than or equal :value characters.',
  67. 'array' => 'The :attribute must have :value items or more.',
  68. ],
  69. 'image' => 'The :attribute 必须是一张图片.',
  70. 'in' => '选项 :attribute 不在给定范围中.',
  71. 'in_array' => 'The :attribute field does not exist in :other.',
  72. 'ip' => 'The :attribute must be a valid IP address.',
  73. 'ipv4' => 'The :attribute must be a valid IPv4 address.',
  74. 'ipv6' => 'The :attribute must be a valid IPv6 address.',
  75. 'json' => 'The :attribute must be a valid JSON string.',
  76. 'lt' => [
  77. 'numeric' => 'The :attribute must be less than :value.',
  78. 'file' => 'The :attribute must be less than :value kilobytes.',
  79. 'string' => 'The :attribute must be less than :value characters.',
  80. 'array' => 'The :attribute must have less than :value items.',
  81. ],
  82. 'lte' => [
  83. 'numeric' => 'The :attribute must be less than or equal :value.',
  84. 'file' => 'The :attribute must be less than or equal :value kilobytes.',
  85. 'string' => 'The :attribute must be less than or equal :value characters.',
  86. 'array' => 'The :attribute must not have more than :value items.',
  87. ],
  88. 'mimes' => 'The :attribute must be a file of type: :values.',
  89. 'mimetypes' => 'The :attribute must be a file of type: :values.',
  90. 'min' => [
  91. 'numeric' => 'The :attribute must be at least :min.',
  92. 'file' => 'The :attribute must be at least :min kilobytes.',
  93. 'string' => 'The :attribute must be at least :min characters.',
  94. 'array' => 'The :attribute must have at least :min items.',
  95. ],
  96. 'not_in' => 'The selected :attribute is invalid.',
  97. 'not_regex' => 'The :attribute format is invalid.',
  98. 'numeric' => 'The :attribute must be a number.',
  99. 'present' => 'The :attribute field must be present.',
  100. 'regex' => 'The :attribute format is invalid.',
  101. 'required_if' => 'The :attribute field is required when :other is :value.',
  102. 'required_unless' => 'The :attribute field is required unless :other is in :values.',
  103. 'required_with' => 'The :attribute field is required when :values is present.',
  104. 'required_with_all' => 'The :attribute field is required when :values are present.',
  105. 'required_without' => 'The :attribute field is required when :values is not present.',
  106. 'required_without_all' => 'The :attribute field is required when none of :values are present.',
  107. 'same' => 'The :attribute and :other must match.',
  108. 'size' => [
  109. 'numeric' => 'The :attribute must be :size.',
  110. 'file' => 'The :attribute must be :size kilobytes.',
  111. 'string' => 'The :attribute must be :size characters.',
  112. 'array' => 'The :attribute must contain :size items.',
  113. ],
  114. 'starts_with' => 'The :attribute must start with one of the following: :values',
  115. 'string' => 'The :attribute must be a string.',
  116. 'timezone' => 'The :attribute must be a valid zone.',
  117. 'unique' => 'The :attribute has already been taken.',
  118. 'uploaded' => 'The :attribute failed to upload.',
  119. 'url' => 'The :attribute format is invalid.',
  120. 'uuid' => 'The :attribute must be a valid UUID.',
  121. ];
  122. }
  123. }