Mohsen's avatar

Pagination With Many to Many Relation

I have tow models with many to many relationship . posts and tags (tag labels for each post). I tried to paginate posts with this code in repository but doesn't work . what this the problem ?

   public function getTagsWithPosts($tagId,$rowsCount)
{
        return $this->tag->where('id',$tagId)->with(['posts' => function($q) use ($rowsCount){
              $q->paginate($rowsCount);
            }])->get();
}
0 likes
3 replies
Mohsen's avatar

@tomi thanks for your answer but I want to know what is the problem in my code

Please or to participate in this conversation.