用户表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。
用户表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。
转载于:https://www.cnblogs.com/eleven24/p/8024358.html