Mehdi Alikhani
Mehdi Alikhani

Reputation: 141

Laravel gives me a duplicate collection data

I want to sort my data by created date with this code :

        $comments = Instacomment::where('postid',$query->post['id'])->orderBy('comment.created_at', 'ASC')->paginate(10);

enter image description here

These are the results and Laravel gives me duplicate data! I don't know what to do !

Upvotes: 1

Views: 251

Answers (1)

Monika
Monika

Reputation: 461

please try join table

        $comments = Instacomment::join('comments', 'instacomment.id', '=', 'comments.postid')->where('postid',$query->post['id'])->orderBy('comment.created_at', 'ASC')->paginate(10);

Upvotes: 2

Related Questions