Skip to content

Instantly share code, notes, and snippets.

@GeniJaho
Created December 24, 2021 15:07
6 - Join team final
<?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