Hello all,
I want to query some data using nested eager loading , but it appears my query only fetch the first relation!
Here are my tables:
users: id
posts: post_id,user_id
commetns: comment_id, post_id,user_id
the models:
User:
public function posts()
{
return $this->hasMany('App\Post');
}
public function comments()
{
return $this->hasMany('App\Comment');
}
Post:
public function user()
{
return $this->belongsTo('App\User','user_id');
}
public function comments()
{
return $this->hasMany('App\Comment');
}
Commetn:
public function post()
{
return $this->belongsTo('App\Post', 'post_id');
}
public function user()
{
return $this->belongsTo('App\User' ,'user_id');
}
my nested eager loading:
$post = Post::with('user.comments')->find($id);
and I get an error on commetns method!
However if I put $post= Post::with('user')->find($id);
it retrieves the post with the user who owns the post.
Now, I want to fetch above along with comments which belongsTo this specific post .
Your thoughts are greatly appreciated!
Thanks in advanced .