public function sendTeamInvitation(Request $request, $teamId)
    {
        $user = $request->user();

        $this->validate($request, [
            'email' => 'required|max:255|email',
        ]);

        $team = $user->teams()
                ->where('owner_id', $user->id)
                ->findOrFail($teamId);

        if ($team->invitations()->where('email', $request->email)->exists()) {
            return response()->json(['email' => 'That user is already invited to the team.'], 422);
        }

        $team->inviteUserByEmail($request->email);

        return $team->fresh(['users', 'invitations']);
    }
public function sendTeamInvitation(Request $request, $teamId)
    {
        $user = $request->user();

        $this->validate($request, [
            'email' => 'required|max:255|email',
        ]);

        $team = $user->teams()
                ->where('owner_id', $user->id)
                ->findOrFail($teamId);

        if ($team->invitations()->where('email', $request->email)->exists()) {
            return response()->json(['email' => 'That user is already invited to the team.'], 422);
        }

        $team->inviteUserByEmail($request->email);

        return $team->fresh(['users', 'invitations']);
    }
public function sendTeamInvitation ( Request $ request , $ teamId ) { $ user = $ request -> user ( ) ; $ this -> validate ( $ request , [ 'email' => 'required|max:255|email' , ] ) ; $ team = $ user -> teams ( ) -> where ( 'owner_id' , $ user -> id ) -> findOrFail ( $ teamId ) ; if ( $ team -> invitations ( ) -> where ( 'email' , $ request -> email ) -> exists ( ) ) { return response ( ) -> json ( [ 'email' => 'That user is already invited to the team.' ] , 422 ) ; } $ team -> inviteUserByEmail ( $ request -> email ) ; return $ team -> fresh ( [ 'users' , 'invitations' ] ) ; }
Send an invitation for the given team.

@param  \Illuminate\Http\Request  $request
@param  string  $teamId
@return \Illuminate\Http\Response
Send an invitation for the given team .