(the question has already been answered in the comments, but the minus also wrote the correct answer)
You cannot use a query scope in Colletion , because a query scope is a concept used by Eloquent to add restrictions to a database query, whereas Collections is just a collection of things (data, objects, etc.).).
In your case, you need to change this line:
$association->members->active()->count();
in
$association->members()->active()->count();
This works because when we call members as a method, we get an instance of QueryBuilder , and with that we can start attaching regions to the query before calling the count method.
source share