用户表user

标签表tag

中间表user_tag(user_id,tag_id)

在user模型中定义tags关联如下:

    public function tags()
    {
        return $this->belongsToMany(Tag::class, 'user_tag');
    }

  上面的belongsToMany方法中的第二个参数 user_tag 是中间表,保存了user_id和tag_id。

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-24
  • 2022-12-23
  • 2022-12-23
  • 2022-03-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案