GlossaryEntryResource.php 952 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Http\Resources\V3;
  3. use App\Models\DhammaTerm;
  4. use Illuminate\Http\Request;
  5. /**
  6. * 词汇表的一条(`dhamma_terms` 表里系统 channel 的术语)。只给客户端本地查词要用的字段;`id` 是术语 guid。
  7. *
  8. * @mixin DhammaTerm
  9. */
  10. class GlossaryEntryResource extends BaseResource
  11. {
  12. /**
  13. * @return array{
  14. * id: string,
  15. * word: string,
  16. * tag: string|null,
  17. * meaning: string,
  18. * other_meaning: string|null
  19. * }
  20. */
  21. public function toArray(Request $request): array
  22. {
  23. $tag = trim((string) $this->tag);
  24. $other = trim((string) $this->other_meaning);
  25. return [
  26. 'id' => (string) $this->guid,
  27. 'word' => (string) $this->word,
  28. 'tag' => $tag === '' ? null : $tag,
  29. 'meaning' => (string) $this->meaning,
  30. 'other_meaning' => $other === '' ? null : $other,
  31. ];
  32. }
  33. }