I have three tables as define below
User
- id
- name
Post
- id
- text
- user_id
Comments
- id
- text
- post_id
This is User model User.php
class User
{
public function post()
{
return $this->hasMany(Post::class);
}
}
This is my post model Post.php
class Post
{
public function comments()
{
return $this->hasMany(Comment::class);
}
}
Issue:
I want to display no.of comments per user using eloquent eager loading.
Can anyone help me with that? Thanks in advance.