I have two tables - Posts and Comments. The relationship between them is one-to-many. A Post has many comments.
I am trying to get a list of all Posts with their latest 2 Comments
I have tried this:
$posts = Post::with(['comments'=>function($query){
$query->latest()->take(2)->get();
}])->get();
But it seems to be working only for the first Post;