IndexTermRequest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Http\Requests\V3;
  3. use App\Models\DhammaTerm;
  4. use App\Services\V3\TermService;
  5. use Illuminate\Foundation\Http\FormRequest;
  6. use Illuminate\Validation\Rule;
  7. /**
  8. * 术语列表(某个 channel / studio 的)的过滤与分页。都是可选叠加的过滤。
  9. */
  10. class IndexTermRequest extends FormRequest
  11. {
  12. public function authorize(): bool
  13. {
  14. return true;
  15. }
  16. /**
  17. * @return array<string, array<int, mixed>>
  18. */
  19. public function rules(): array
  20. {
  21. return [
  22. 'search' => ['sometimes', 'nullable', 'string', 'max:128'],
  23. 'quality' => ['sometimes', 'string', Rule::in(DhammaTerm::QUALITIES)],
  24. 'category' => ['sometimes', 'string', 'max:128'],
  25. // 查询串里是字符串:Laravel 的 boolean 规则不收 "true"/"false",取值处用 \$request->boolean()
  26. 'general' => ['sometimes', 'in:true,false,1,0'],
  27. 'order' => ['sometimes', 'string', Rule::in(TermService::ORDERS)],
  28. 'dir' => ['sometimes', 'in:asc,desc'],
  29. 'page' => ['integer', 'min:1'],
  30. 'per_page' => ['integer', 'min:1', 'max:200'],
  31. ];
  32. }
  33. }