UpdateChannelLinksRequest.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Http\Requests\V3;
  3. use App\Models\ChannelLink;
  4. use App\Services\V3\ChannelLinkService;
  5. use Illuminate\Foundation\Http\FormRequest;
  6. /**
  7. * `PATCH /v3/channels/{channel}/links` 的入参:传了哪个键就整体替换哪一种关系,没有必填项。
  8. *
  9. * 目标是否存在、看不看得见、是不是自己、逐词类型对不对,在 {@see ChannelLinkService} 里判。
  10. */
  11. class UpdateChannelLinksRequest extends FormRequest
  12. {
  13. /** 登录与权限在中间件 / Service 里判 */
  14. public function authorize(): bool
  15. {
  16. return true;
  17. }
  18. /**
  19. * @return array<string, array<int, mixed>>
  20. */
  21. public function rules(): array
  22. {
  23. return [
  24. 'derived_from' => ['sometimes', 'nullable', 'uuid'],
  25. 'wbw' => ['sometimes', 'nullable', 'uuid'],
  26. 'fallback' => ['sometimes', 'array', 'max:'.ChannelLink::LISTS[ChannelLink::FALLBACK]],
  27. 'fallback.*' => ['uuid', 'distinct'],
  28. 'term_source' => ['sometimes', 'array', 'max:'.ChannelLink::LISTS[ChannelLink::TERM_SOURCE]],
  29. 'term_source.*' => ['uuid', 'distinct'],
  30. ];
  31. }
  32. }