/** * Attach a user to a given team based on their invitation. * * @param string $invitationId * @param \Illuminate\Contracts\Auth\Authenticatable $user * @return void */ public function attachUserToTeamByInvitation($invitationId, $user) { $userModel = get_class($user); $inviteModel = get_class((new $userModel())->invitations()->getQuery()->getModel()); $invitation = (new $inviteModel())->where('token', $invitationId)->first(); if ($invitation) { $invitation->team->users()->attach([$user->id], ['role' => Spark::defaultRole()]); $user->switchToTeam($invitation->team); $invitation->delete(); } }
/** * Customize the roles that may be assigned to team members. * * @return void */ protected function customizeRoles() { Spark::defaultRole('member'); Spark::roles(['admin' => 'Administrator', 'member' => 'Member']); }
/** * Join the team with the given ID. * * @param int $teamId * @return void */ public function joinTeamById($teamId) { $this->teams()->attach([$teamId], ['role' => Spark::defaultRole()]); $this->currentTeam(); event(new JoinedTeam($this, $this->teams()->find($teamId))); }
/** * Join the team with the given ID. * * @param int $teamId * @return void */ public function joinTeamById($teamId) { $this->teams()->attach([$teamId], ['role' => Spark::defaultRole()]); $this->currentTeam(); }
/** * {@inheritdoc} */ public function handle($team, $user, $role = null) { $team->users()->attach($user, ['role' => $role ?: Spark::defaultRole()]); event(new TeamMemberAdded($team, $user)); }