Get relation count Laravel JSON

I have a Post model where has many comments via hasMany('App/Comment') relation. I am trying to return the number of comments in JSON format. The response I would like to get is like

comments: [...],
numComments: 5,
...

I am able to return the comments but I don't know whether there is an easy way to get number of comments with eager loading.

Post::whereIn('user_id', $ids)->with('comments')->get();

Thanks.

Answers


Just found the solution here.


Need Your Help

Using CSS transform scale maintains original positioning

css3 transform

When using the transform: scale() property, elements that are floated next to each other act like their full-size counterparts even after the scaling.