dimanche 2 septembre 2018

Count instances of many to many relationship : Laravel

I have a database setup where you have a lecturer having many groups and each group having many students and also a student can be in many groups. Therefore I have a one to many relationship between a lecturer and groups (respectively) and a many to many relationship between students and groups.

I want to show the lecturer how many students they have overall. For example if the lecturer has 5 groups with 5 students in each then I want to show 25. I tried this auth()->user()->userable->groups()->withCount('students') but I got this:

Call to a member function getRelationExistenceCountQuery() on null

What's the most efficient way to get my desired result?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire