Laravel

Using loadCount for Relationship Count Queries 💡

Using the loadCount method, you may load a relationship count after the parent model has already been retrieved.

$post = Post::find(1);

// Eager load the count of comments without loading all comment data
$post->loadCount('comments');

echo $post->comments_count; // Outputs the number of comments

More details: link