Skip to content

Best practice to count group members #512

Answered by stevebauman
klepptor asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @klepptor!

I've just added a method for this in the latest v2.18.0 release.

This method (count()) will execute a query on your LDAP server for all members the group, but restrict the query to only return objectclass, trimming down the result size and speeding up the result.

Here is how you can utilize this method:

$group = Group::findByOrFail('distinguishedName', $groupDN);

$countOfMembers = $group->members()->count();

However, the fastest way would be to count the member attribute on your resulting $group model, if your server returns the full list (which may not be the case with larger groups):

// Notice the last argument in the below method, asking the LDAP
// server to only return…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@klepptor
Comment options

@stevebauman
Comment options

Answer selected by klepptor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants