LookupTermRequest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Http\Requests\V3;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. /**
  5. * `GET /v3/terms`:按词查。word 必填(逗号分隔,最多 50 个)。
  6. */
  7. class LookupTermRequest extends FormRequest
  8. {
  9. public function authorize(): bool
  10. {
  11. return true;
  12. }
  13. /**
  14. * @return array<string, array<int, mixed>>
  15. */
  16. public function rules(): array
  17. {
  18. return [
  19. 'word' => ['required', 'string', 'max:2048', function (string $attribute, mixed $value, \Closure $fail) {
  20. if (count(array_filter(explode(',', (string) $value), fn ($w) => trim($w) !== '')) > 50) {
  21. $fail(__('validation.max.array', ['attribute' => $attribute, 'max' => 50]));
  22. }
  23. }],
  24. 'tag' => ['sometimes', 'nullable', 'string', 'max:1024'],
  25. 'channel' => ['sometimes', 'uuid'],
  26. 'language' => ['sometimes', 'string', 'max:16'],
  27. // 查询串里是字符串:Laravel 的 boolean 规则不收 "true"/"false",取值处用 \$request->boolean()
  28. 'with_body' => ['sometimes', 'in:true,false,1,0'],
  29. 'page' => ['integer', 'min:1'],
  30. 'per_page' => ['integer', 'min:1', 'max:200'],
  31. ];
  32. }
  33. }