The code:
$posts = Jumpsite::find($jid)
->posts()
->with(\'comments\')
->with(\'likes\')
->with(\
In your model place the following accessors:
Count total Likes:
public function getTotalLikesAttribute()
{
return $this->hasMany('Like')->whereUserId($this->author_id)->count();
}
Count total comments:
From your description, i can see, you have retrieving the number of posts as comments
public function getTotalCommentsAttribute()
{
return $this->hasMany('Post')->whereUserId($this->author_id)->count();
}
Now, from your controller:
$post = Jumpsite::find($jid);
// total comments
var_dump( $post->total_comments );
// total Likes
var_dump( $post->total_likes );