Something like
$managers = Manager::withCount('universities');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Need help about counting relevant data with hierarchy(proposed solution - recurring mysql)
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Role</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td>{{ $user->role }}</td>
</tr>
</tbody>
</table>
There is an array of managers hierarchy
$managerLevels = [ 'level' => 1, 'designation' => 'chairman', 'level' => 2, 'designation' => 'vice chairman', 'level' => 3, 'designation' => 'secretary', 'level' => 4, 'designation' => 'assistant secretary', 'level' => 5, 'designation' => 'member', ];
There are following tables
Hence managers are connected with parent id from same table
| 12 | NULL | 1 | 13 | 12 | 2 | 14 | NULL | 1 | 15 | 14 | 2 | 16 | 12 | 2 | 17 | 15 | 3 | 18 | 17 | 4 | 19 | 18 | 5 | 20 | 10 | 5
Only lowest level manager is connected with universities table Hence manager_id is the lowest level (hence lowest level = 5) manager from managers table
Please or to participate in this conversation.