[Vuejs]-Laravel Vue add user details to comment array

0👍

Use nested eager loading.

$comments = Post::with('comments.user')->where('id', $id)->first()->comments;

That should retrieve all comments with its user relationship.

foreach($comments as $comment)
{
    echo $comment->user->id;
}

Or I believe you can also do this. (Lazy Eager loading)

$post = Post::find($id);
$post->load('comments.user');
$comments = $post->comments;
👤Wreigh

Leave a comment