The code:
$posts = Jumpsite::find($jid)
->posts()
->with(\'comments\')
->with(\'likes\')
->with(\
Count comments for all blog posts in laravel
Step 1: Place this code inside your ‘Post’ model.
// Get the comments for the blog post.
public function comments()
{
return $this->hasMany('App\Comment');
}
Step 2: Place this code inside your ‘PostController’ controller.
$posts= Post::all();
return view('home')->with('posts', $posts);
Step 3: Then count comments for all posts using the below code.
@foreach($posts as $row)
{{$row->comments->count()}}
@endforeach
See details here: http://www.pranms.com/count-comments-for-all-blog-posts-in-laravel/