我有这样的东西:
class User
{
protected $with = ['organisation'];
}
class Group
{
public function members(): BelongsToMany
{
return $this->belongsToMany(User::class, 'groups_members', 'group_id', 'user_id', 'id', 'id')
->select(['users.id', 'users.name', 'users.email']);
}
}
如何防止组成员加载组织关系?
答案 0 :(得分:1)
您可以使用without()
:
public function members(): BelongsToMany
{
return $this->belongsToMany(User::class, 'groups_members', 'group_id', 'user_id', 'id', 'id')
->select(['users.id', 'users.name', 'users.email'])
->without('organisation');
}