I am doing it this way
Post model
public function comments3() {
return $this->morphMany('Comment','commentable')->limit(3)->orderBy('created_at','desc');
}
And view
@foreach ($post->comments3->reverse() as $comment)
//code
@endforeach
I am using polymoprhic relations as another models can have comment too. In your case just switch morphMany to hasMany
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community