IndexStudioChannelRequest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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/studios/{studio}/channels` 的入参:某个 studio(本人或团队)的工作区列表。
  8. */
  9. class IndexStudioChannelRequest 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. 'relation' => ['sometimes', 'in:own,shared,all'],
  26. 'collaborator' => ['sometimes', 'uuid'],
  27. 'search' => ['sometimes', 'nullable', 'string', 'max:128'],
  28. 'type' => ['sometimes', 'string', Rule::in(IndexChannelRequest::TYPES)],
  29. 'lang' => ['sometimes', 'string', 'max:16'],
  30. // 不能用 sometimes:缺 book 时 sometimes 会跳过整条规则,required_with 就不生效
  31. 'book' => ['required_with:para', 'integer', 'min:1'],
  32. 'para' => ['required_with:book', 'integer', 'min:1'],
  33. 'order' => ['sometimes', 'string', Rule::in(ChannelService::ORDERS)],
  34. 'dir' => ['sometimes', 'in:asc,desc'],
  35. 'page' => ['integer', 'min:1'],
  36. 'per_page' => ['integer', 'min:1', 'max:200'],
  37. ];
  38. }
  39. }