ProgressChapter.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. class ProgressChapter extends Model
  6. {
  7. use HasFactory;
  8. protected $fillable = [
  9. 'book',
  10. 'book',
  11. 'channel_id',
  12. 'lang' => 'en',
  13. 'all_trans',
  14. 'public',
  15. 'progress',
  16. 'title',
  17. 'created_at',
  18. 'updated_at'
  19. ];
  20. protected $casts = [
  21. 'uid' => 'string'
  22. ];
  23. protected $primaryKey = 'uid';
  24. //protected $dateFormat = 'U';
  25. public function tagid()
  26. {
  27. return $this->hasOne('App\Models\TagMap', 'anchor_id', 'uid'); //参数一:需要关联的子表类名,前面必须加上命名空间 参数二:子表关联父表的字段 参数三:父表关联子表的字段
  28. }
  29. public function tags()
  30. {
  31. return $this->belongsToMany('App\Models\Tag', 'tag_maps', 'anchor_id', 'tag_id');
  32. }
  33. /**
  34. * 关联到 Channel 模型
  35. * channel_id 关联到 channel 表的 uid 字段
  36. */
  37. public function channel()
  38. {
  39. return $this->hasOne(Channel::class, 'uid', 'channel_id');
  40. }
  41. public function views()
  42. {
  43. return $this->hasMany('App\Models\View', 'target_id', 'uid');
  44. }
  45. }