Closed ziming closed 9 years ago
Hi,
On your user model use:
$user->teams()->sync([]);
And for your team:
$team->users()->sync([]);
To remove all related models.
Ah thank you, gonna try it soon and just wondering if I do either of the above and the user now has no team, does current_team_id automatically become null?
No, you would still need to call $user->switchTeam( null );
in order to reset the current team.
Thank you. Another question.
If I do
$team->users()->sync($listOfUserIds);
If it is the users first team, do their current_team_id get updated with that team id?
No, the sync
method is the standard Laravel behavior. You would need to take care of this yourself.
Hi,
I'm not sure if this feature is already supported but I think something like detachAllTeams or detachAllUsers would be useful when I'm only allowing 1 person to belong to 1 team. So that on my edit team page, I can either remove everyone in team X instantly or get all users currently belonging to team X, remove all their teams associations then grab the form select submission and assign those to team X