ChannelLink.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Models;
  3. use App\Services\V3\ChannelLinkService;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. /**
  7. * channel 之间的一条关系(`channel_links` 表):channel_uid 指向 target_uid,kind 说明是哪种关系。
  8. *
  9. * 只给 v3 用,读写经 {@see ChannelLinkService}。
  10. */
  11. class ChannelLink extends Model
  12. {
  13. /** 继承自(如英文版译自中文版)。单值,只记录 */
  14. public const DERIVED_FROM = 'derived_from';
  15. /** 降级:段落没有数据时改取的 channel。有序,由客户端拼接 */
  16. public const FALLBACK = 'fallback';
  17. /** 捆绑的逐词 channel,载入时当原文。单值 */
  18. public const WBW = 'wbw';
  19. /** 术语路径:从哪些 channel 取术语。有序 */
  20. public const TERM_SOURCE = 'term_source';
  21. /** 单值的 kind */
  22. public const SINGLE = [self::DERIVED_FROM, self::WBW];
  23. /** 有序列表的 kind → 条数上限 */
  24. public const LISTS = [self::FALLBACK => 3, self::TERM_SOURCE => 10];
  25. protected $fillable = ['channel_uid', 'kind', 'target_uid', 'position'];
  26. protected function casts(): array
  27. {
  28. return ['position' => 'integer'];
  29. }
  30. public function target(): BelongsTo
  31. {
  32. return $this->belongsTo(Channel::class, 'target_uid', 'uid');
  33. }
  34. }