team->members() ->whereRaw('LOWER(email) = ?', [$email]) ->exists(); if ($isMember) { $fail(__('This user is already a member of the team.')); return; } $hasPendingInvitation = TeamInvitation::where('team_id', $this->team->id) ->whereRaw('LOWER(email) = ?', [$email]) ->whereNull('accepted_at') ->where(function ($query) { $query->whereNull('expires_at') ->orWhere('expires_at', '>', now()); }) ->exists(); if ($hasPendingInvitation) { $fail(__('An invitation has already been sent to this email address.')); } } }