Closed ziming closed 9 years ago
Don't know if this is a good idea to use the properties for this.
I'd prefer to do this with the Teamwork helper methods.
So I see two possible solutions:
First: Chain attach team and switch team (not working right now!)
$user->attachTeam( $newTeam )->switchTeam( $newTeam );
Second: Give the attachTeam
method a second parameter to determine if the team should be automatically set as the current team. (Defaults to false)
$user->attachTeam( $newTeam, true )
I'd personally prefer the second approach.
Thoughts?
I think I prefer the second approach. Though for me the main reason I ask this question is because for my app, 1 user can only be in 1 team. Hence I thought doing that that would allow me to avoid making attach and detach calls.
I tried just $user->switchTeam($currentTeamId) but I got a user not in team exception
Yep, the switchTeam
method makes a check to see if the user is allowed to switch to this team.
Okay, then I'd make a change that the detachTeam
method can be chainable.
So it would become:
$user->detachTeam( $user->currentTeam )->attachTeam( $newTeam );
This way the attachTeam
method doesn't need a second parameter, because if current_team_id
is NULL it will be set automatically.
Done!
Thank you.
Hi,
I think it may be good if by doing $user->current_team_id = 5;
An appropriate record in team_user pivot is created if it previously did not exist.