UpdateChannelRequest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Http\Requests\V3;
  3. use App\Models\Channel;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. use Illuminate\Validation\Rule;
  6. /**
  7. * `PATCH /v3/channels/{channel}` 的入参:改 channel 信息。只做局部更新,没有必填项。
  8. */
  9. class UpdateChannelRequest 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. 'name' => ['sometimes', 'string', 'max:128'],
  26. 'type' => ['sometimes', 'string', Rule::in(IndexChannelRequest::TYPES)],
  27. 'lang' => ['sometimes', 'string', 'max:16'],
  28. 'summary' => ['sometimes', 'nullable', 'string', 'max:1024'],
  29. 'status' => ['sometimes', 'integer', Rule::in([Channel::STATUS_PRIVATE, Channel::STATUS_UNLISTED, Channel::STATUS_PUBLIC])],
  30. 'source_type' => ['sometimes', 'string', Rule::in(['original', 'reprint', 'ai'])],
  31. 'source_id' => ['sometimes', 'nullable', 'string', 'max:36'],
  32. 'config' => ['sometimes', 'nullable', 'array'],
  33. ];
  34. }
  35. }