StoreTermRequest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. * 新建术语(`POST /v3/channels/{channel}/terms`、`POST /v3/studios/{studio}/terms`)。
  8. *
  9. * studio 级术语要给 language;channel 里的跟 channel 的语言,传了也不用。分类写在 note 的 {{category|…}} 里。
  10. */
  11. class StoreTermRequest extends FormRequest
  12. {
  13. public function authorize(): bool
  14. {
  15. return true;
  16. }
  17. /**
  18. * @return array<string, array<int, mixed>>
  19. */
  20. public function rules(): array
  21. {
  22. $isStudio = $this->route('studio') !== null;
  23. return [
  24. 'word' => ['required', 'string', 'max:1024'],
  25. 'tag' => ['sometimes', 'nullable', 'string', 'max:1024', 'not_regex:/@/'],
  26. 'meaning' => ['required', 'string', 'max:1024'],
  27. 'other_meaning' => ['sometimes', 'nullable', 'string', 'max:1024'],
  28. 'note' => ['sometimes', 'nullable', 'string'],
  29. 'summary' => ['sometimes', 'nullable', 'string'],
  30. 'quality' => ['sometimes', 'nullable', 'string', Rule::in(DhammaTerm::QUALITIES)],
  31. 'content_type' => ['sometimes', 'string', Rule::in(DhammaTerm::CONTENT_TYPES)],
  32. 'redirect' => ['sometimes', 'nullable', 'string', 'max:1024'],
  33. 'language' => [$isStudio ? 'required' : 'prohibited', 'string', 'max:16'],
  34. ];
  35. }
  36. }