Hello all,
I'm working on a blog, with pages > comments > replies to comment
So a page has comments :
public function comments()
{
return $this->hasMany(WpComment::class, 'wp_page_id', 'id')->where('status', 'approved')->where('wp_comment_id', 0);
}
and a comment has replies:
public function replies()
{
return $this->hasMany(WpComment::class, 'wp_comment_id')->where('status', 'approved');
}
Now i'm querying a page, with comments, and I need to count Comments with Replies, but I'm struggling to do it:
WpPage::query()
->select('id', 'title', 'sections', 'header', 'blocks', 'breadcrumb', 'type', 'wp_media_id', 'wp_user_id')
->where(['link' => $pageLink])
->withCount('comments')
->with('comments:id,wp_page_id,author,content' )
->firstOrFail();
For now, I get the count of Comments but without Replies.
How would you do that? do I need to search about "Counting Related Models On Morph To Relationships"?
Thank you in advance,
Cyril