UpdateTermRequest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Http\Requests\V3;
  3. use App\Models\DhammaTerm;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. use Illuminate\Validation\Rule;
  6. /**
  7. * `PATCH /v3/terms/{term}`:只改传了的字段。word / tag 建立后不准改(引用方写 `[[word@tag]]`),
  8. * 要改就新建一条、把旧的 redirect 过去。乐观锁的 If-Match 在 Service 里判。
  9. */
  10. class UpdateTermRequest extends FormRequest
  11. {
  12. public function authorize(): bool
  13. {
  14. return true;
  15. }
  16. /**
  17. * @return array<string, array<int, mixed>>
  18. */
  19. public function rules(): array
  20. {
  21. return [
  22. 'word' => ['prohibited'],
  23. 'tag' => ['prohibited'],
  24. 'meaning' => ['sometimes', 'string', 'max:1024'],
  25. 'other_meaning' => ['sometimes', 'nullable', 'string', 'max:1024'],
  26. 'note' => ['sometimes', 'nullable', 'string'],
  27. 'summary' => ['sometimes', 'nullable', 'string'],
  28. 'quality' => ['sometimes', 'nullable', 'string', Rule::in(DhammaTerm::QUALITIES)],
  29. 'content_type' => ['sometimes', 'string', Rule::in(DhammaTerm::CONTENT_TYPES)],
  30. 'redirect' => ['sometimes', 'nullable', 'string', 'max:1024'],
  31. 'language' => ['sometimes', 'string', 'max:16'],
  32. ];
  33. }
  34. /**
  35. * @return array<string, string>
  36. */
  37. public function messages(): array
  38. {
  39. return [
  40. 'word.prohibited' => __('messages.term_word_immutable'),
  41. 'tag.prohibited' => __('messages.term_word_immutable'),
  42. ];
  43. }
  44. }