dimanche 26 novembre 2017

I'm trying to load only the last 3 comments on every post

i want get all posts with last three comment on each post. my relation is

public function comments()
{
   return $this->hasMany('App\Commentpostfeed','post_id')->take(3);
}

This would return only 3 comments total whenever I called it instead of 3 comments per post. i use this way :

1 :

Postfeed::with(['comment' => function($query) {
         $query->orderBy('created_at', 'desc')->take(3); }]);

2 :

 $postings = Postfeed::with('comments')->get();

but getting same result. please help me out for this problem.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2AaPCj2
via IFTTT

Aucun commentaire:

Enregistrer un commentaire