public detachTeam ( mixed $team ) | ||
$team | mixed |
public function detachTeam($team)
{
$team = $this->retrieveTeamId($team);
$this->teams()->detach($team);
event(new UserLeftTeam($this, $team));
if ($this->relationLoaded('teams')) {
$this->load('teams');
}
/**
* If the user has no more teams,
* unset the current_team_id
*/
if ($this->teams()->count() === 0 || $this->current_team_id === $team) {
$this->current_team_id = null;
$this->save();
if ($this->relationLoaded('currentTeam')) {
$this->load('currentTeam');
}
}
return $this;
}