Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
You are trying to select a post with comments.
Do you need comments? So choose comments.
Comment::whereHas('post', function( $query ) use ($id) {
$query->whereId($id);
})->orderBy('created_at')->paginate(0, 15);
Try like this:
$posts = Post::with('comments')
->join('comments', 'comments.post_id', '=', 'posts.id')
->select('posts.*', 'comments.*')
->groupBy('posts.id')
->orderBy(DB::raw('COUNT(`posts`.`id`)'), 'asc')
->paginate(10);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question