public function switchTeam($team)
{
if ($team !== 0 && $team !== null) {
$team = $this->retrieveTeamId($team);
$teamModel = Config::get('teamwork.team_model');
$teamObject = (new $teamModel())->find($team);
if (!$teamObject) {
$exception = new ModelNotFoundException();
$exception->setModel($teamModel);
throw $exception;
}
if (!$teamObject->users->contains($this->getKey())) {
$exception = new UserNotInTeamException();
$exception->setTeam($teamObject->name);
throw $exception;
}
}
$this->current_team_id = $team;
$this->save();
if ($this->relationLoaded('currentTeam')) {
$this->load('currentTeam');
}
return $this;
}