if comments belongs to a post you can call it that way inside a foreach loop
Comment Model:
public function post(){
return $this->belongsTo('App\Post');
}
In your Controller
$recentcomment = Comment::latest();
// I believe latest gives you an array of latest comments.
// If you only want one comment use latest()->first();
foreach($recentcomment as $comment){
$post_title = $comment->post->title;
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community