StoreMeReactionRequest.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Http\Requests\V3;
  3. use App\Models\Reaction;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. use Illuminate\Validation\Rule;
  6. /**
  7. * `POST /v3/me/reactions` 的入参:添加一条自己的 reaction。
  8. *
  9. * 不收 user_id:v2 允许 `user_id` 覆盖操作者(替别人加关注),那是 target 的
  10. * 关注者管理,不属于 `me` 这组端点,留在 v2。
  11. */
  12. class StoreMeReactionRequest extends FormRequest
  13. {
  14. /**
  15. * 登录检查在控制器里做:authorize() 返回 false 会渲染成 403,
  16. * 而「没登录」应该是 401。
  17. */
  18. public function authorize(): bool
  19. {
  20. return true;
  21. }
  22. /**
  23. * @return array<string, array<int, mixed>>
  24. */
  25. public function rules(): array
  26. {
  27. return [
  28. 'type' => ['required', 'string', Rule::in(Reaction::TYPES)],
  29. 'target_id' => ['required', 'uuid'],
  30. 'target_type' => ['required', 'string', Rule::in(Reaction::TARGET_TYPES)],
  31. // context 列是 varchar(128)
  32. 'context' => ['nullable', 'string', 'max:128'],
  33. ];
  34. }
  35. }