Assuming you use Eloquent and your models are called Book and User with a Many-to-Many relationship between them, you could do something like:
Book::has(users)->count();
This will give you the count of all books which have at least one user associated. It will be converted to an inner join internally.