File tree Expand file tree Collapse file tree 2 files changed +20
-8
lines changed
Expand file tree Collapse file tree 2 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -24,14 +24,30 @@ public function isCurrentTeam($team)
2424 public function currentTeam ()
2525 {
2626 if (is_null ($ this ->current_team_id ) && $ this ->id ) {
27- $ this ->forceFill ([
28- 'current_team_id ' => $ this ->personalTeam ()->id ,
29- ])->save ();
27+ $ this ->switchTeam ($ this ->personalTeam ());
3028 }
3129
3230 return $ this ->belongsTo (Jetstream::teamModel (), 'current_team_id ' );
3331 }
3432
33+ /**
34+ * Switch the user's context to the given team.
35+ *
36+ * @return bool
37+ */
38+ public function switchTeam ($ team )
39+ {
40+ if (!$ this ->belongsToTeam ($ team )) {
41+ return false ;
42+ }
43+
44+ $ this ->forceFill ([
45+ 'current_team_id ' => $ team ->id ,
46+ ])->save ();
47+
48+ return true ;
49+ }
50+
3551 /**
3652 * Get all of the teams the user owns or belongs to.
3753 *
Original file line number Diff line number Diff line change @@ -18,14 +18,10 @@ public function update(Request $request)
1818 {
1919 $ team = Jetstream::newTeamModel ()->findOrFail ($ request ->team_id );
2020
21- if (! $ request ->user ()->belongsToTeam ($ team )) {
21+ if (! $ request ->user ()->switchTeam ($ team )) {
2222 abort (403 );
2323 }
2424
25- $ request ->user ()->forceFill ([
26- 'current_team_id ' => $ team ->id ,
27- ])->save ();
28-
2925 return redirect (config ('fortify.home ' ), 303 );
3026 }
3127}
You can’t perform that action at this time.
0 commit comments