2
0

IndexEditableChannelRequest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Http\Requests\V3;
  3. use App\Services\V3\ChannelService;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. use Illuminate\Validation\Rule;
  6. /**
  7. * `GET /v3/channels/editable` 的入参:我能写内容的 channel(跨 studio)。
  8. */
  9. class IndexEditableChannelRequest extends FormRequest
  10. {
  11. /**
  12. * 登录与权限在中间件 / Service 里判:authorize() 返回 false 会渲染成 403,
  13. * 而「没登录」应该是 401、无权要带具体文案。
  14. */
  15. public function authorize(): bool
  16. {
  17. return true;
  18. }
  19. /**
  20. * @return array<string, array<int, mixed>>
  21. */
  22. public function rules(): array
  23. {
  24. return [
  25. 'search' => ['sometimes', 'nullable', 'string', 'max:128'],
  26. 'type' => ['sometimes', 'string', Rule::in(IndexChannelRequest::TYPES)],
  27. 'lang' => ['sometimes', 'string', 'max:16'],
  28. // 不能用 sometimes:缺 book 时 sometimes 会跳过整条规则,required_with 就不生效
  29. 'book' => ['required_with:para', 'integer', 'min:1'],
  30. 'para' => ['required_with:book', 'integer', 'min:1'],
  31. 'order' => ['sometimes', 'string', Rule::in(ChannelService::ORDERS)],
  32. 'dir' => ['sometimes', 'in:asc,desc'],
  33. 'page' => ['integer', 'min:1'],
  34. 'per_page' => ['integer', 'min:1', 'max:200'],
  35. ];
  36. }
  37. }