I am making a blog and it has some weird issue. I used OneToMany joins between comments and posts model(one post can have many comments) on post model:
public function comments(){
return $this->hasMany('App\Comment');
}
and on comment model:
public function Posts(){
return $this->belongsTo('App\Posts');
}
now the problem i encountered is in show.blade.php which receives data from controller from show() method of controller and returns some data in view about posts.
public function show($id)
{
$post = Posts::find($id);
return view('posts.show')->with('post', $post);
}
and from blade template, I am showing comments related with that post acc to postid
<div class="card-body">
<h5 class="card-title"><strong>test comment:</strong></h5>
<p class="card-text">{{$post->comments->body}}</p>
</div>
when I display the comment in blade removing body I get this:
i tried $post->comments->body
but i get error
what is wrong with this, the suggestion would be appreciated