I have a case where I want to load all elements from one table (all my users), and see how ma ny phones they have. I know it's possible to load all phones, but this will result in too big querys. How can I just load the number of phones and not their content.
My current code (working, but retrieves too big results)
$users= User::get();
$users->load('phones');
I don't want to do a foreach as I don't want to have a N+1 select issue
I don't want to count the array in PHP as it is not optimal (retrieving everything from the DB to just do the count)
None of the already asked questions is satisfactory:
Laravel eloquent counting a relation uses n+1 querys
laravel 4 eloquent eager load relation count doesn't work at all