我有下面的模式:
class Group extends Model
{
/**
* The users that belong to the group.
*/
public function users()
{
return $this->belongsToMany(User::class)->withTimestamps();
}
}
我的User
模型在另一面应该是什么样子?
class User extends Model
{
/**
* The group that owns the user.
*/
public function group()
{
return $this->???(Group::class)->withTimestamps();
}
}
1条答案
按热度按时间iezvtpos1#
它也是belongsToMany,正好相反。试试这个范例:
其中显式参数为:
1.相关型号
1.表(透视表)
1.外部透视键
1.相关透视关键字