/6-join-team-final.php Secret
Created
December 24, 2021 15:07
6 - Join team final
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
... | |
public function join(JoinTeamRequest $request, JoinTeamAction $action) | |
{ | |
/** @var User $user */ | |
$user = Auth::user(); | |
/** @var Team $team */ | |
$team = Team::whereIdentifier($request->identifier)->first(); | |
// Check the user is not already in the team | |
if ($user->teams()->whereTeamId($team->id)->exists()) { | |
return ['success' => false, 'msg' => 'already-joined']; | |
} | |
$action->run($user, $team); | |
return [ | |
'success' => true, | |
'team' => $team->fresh(), | |
'activeTeam' => $user->fresh()->team()->first() | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment