File tree 2 files changed +20
-8
lines changed
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)
24
24
public function currentTeam ()
25
25
{
26
26
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 ());
30
28
}
31
29
32
30
return $ this ->belongsTo (Jetstream::teamModel (), 'current_team_id ' );
33
31
}
34
32
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
+
35
51
/**
36
52
* Get all of the teams the user owns or belongs to.
37
53
*
Original file line number Diff line number Diff line change @@ -18,14 +18,10 @@ public function update(Request $request)
18
18
{
19
19
$ team = Jetstream::newTeamModel ()->findOrFail ($ request ->team_id );
20
20
21
- if (! $ request ->user ()->belongsToTeam ($ team )) {
21
+ if (! $ request ->user ()->switchTeam ($ team )) {
22
22
abort (403 );
23
23
}
24
24
25
- $ request ->user ()->forceFill ([
26
- 'current_team_id ' => $ team ->id ,
27
- ])->save ();
28
-
29
25
return redirect (config ('fortify.home ' ), 303 );
30
26
}
31
27
}
You can’t perform that action at this time.
0 commit comments