Tweaking Eloquent relations – how to get hasMany relation count efficiently?

When working with relationships, most likely you need to get count of related models in many places. There are obvious ways to achieve this of course, but not always efficient. Especially when you are loading a collection of models and their relations. So let me show you what we can do about it!

http://softonsofa.com/tweaking-eloquent-relations-how-to-get-hasmany-relation-count-efficiently/