laravelista / comments

Native comments for your Laravel application.
MIT License
744 stars 142 forks source link

Comment counts #149

Closed QBLes closed 3 years ago

QBLes commented 3 years ago

Is there a way to use say $post->comments->count() but not have it count the "child comments/replies" only the main comments?

Thanks, Les

mabasic commented 3 years ago

This should do:

$post->comments->where('child_id', '')->count();

or

$post->approvedComments->where('child_id', '')->count();

See https://github.com/laravelista/comments/blob/master/resources/views/components/comments.blade.php for reference.

QBLes commented 3 years ago

wow so simple, this is why i love this package, Thanks heaps

QBLes commented 3 years ago

Might be a stupid question but is there an easy way to get the users name (username in my case) as well? for example i used the following on a show all posts page so shows comment count for each post but i also need next to use "created_at" and Username of the comment.. Thanks champion

mabasic commented 3 years ago

Instead of sending you the answer I am sending you a place where to look for stuff like that:

https://github.com/laravelista/comments/blob/master/src/Comment.php#L57

QBLes commented 3 years ago

Sorry, still learning Laravel and how models and such work.. im not the most smartest cookie in the gorup lol

mabasic commented 3 years ago

You'll get there. Just keep trying <3

QBLes commented 3 years ago

Thanks bud!