ProgressChapter.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 = ['book' , 'book', 'channel_id','lang'=>'en',
  9. 'all_trans','public','progress',
  10. 'title','created_at','updated_at'];
  11. protected $casts = [
  12. 'uid' => 'string'
  13. ];
  14. protected $primaryKey = 'uid';
  15. //protected $dateFormat = 'U';
  16. public function tagid()
  17. {
  18. return $this->hasOne('App\Models\TagMap', 'anchor_id', 'uid'); //参数一:需要关联的子表类名,前面必须加上命名空间 参数二:子表关联父表的字段 参数三:父表关联子表的字段
  19. }
  20. public function tags()
  21. {
  22. return $this->belongsToMany('App\Models\Tag','tag_maps','anchor_id','tag_id');
  23. }
  24. public function channel()
  25. {
  26. return $this->hasOne('App\Models\Channel', 'uid', 'channel_id'); //参数一:需要关联的子表类名,前面必须加上命名空间 参数二:子表关联父表的字段 参数三:父表关联子表的字段
  27. }
  28. public function views()
  29. {
  30. return $this->hasMany('App\Models\View', 'target_id', 'uid');
  31. }
  32. }