Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rvabrazaldo's avatar

How to count hasMany relationship

Hi! I'm new at Laravel and I'm loving it!

I have Users and Groups table which has one to many and many to one relationship eloquently set up-ed.

When I do dd( Groups::with('users')->get() );

I could get the groups and all related users to it, its very cool but this time all I want is the count of users related to the group.

0 likes
1 reply

Please or to participate in this conversation.