TagMap.php 759 B

123456789101112131415161718192021222324252627
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. class TagMap extends Model
  6. {
  7. protected $primaryKey = 'id';
  8. protected $keyType = 'string';
  9. protected $casts = [
  10. 'id' => 'string'
  11. ];
  12. protected $fillable = ['table_name' , 'anchor_id', 'tag_id'];
  13. use HasFactory;
  14. public function progresschapter()
  15. {
  16. return $this->belongsTo('App\Models\ProgressChapter', 'anchor_id', 'uid'); //参数一:需要关联的父表类名,前面必须加上命名空间 注意:参数二:子表关联父表的字段 参数三:父表关联子表的字段
  17. }
  18. public function tags()
  19. {
  20. return $this->hasOne('App\Models\Tag', 'tag_id', 'id');
  21. }
  22. }