Dev0ps's avatar

How to calculate the total likes of all posts of a user

i need to count users all posts like

```

$post = Post::whereUserId(auth::id())->get('id');

$postlikes = PostLike::wherePostId($post)->count('post_id);


it's work in foreach. but I am looking for some more convenient way

0 likes
4 replies
jdc1898's avatar

Did you try this?

$post = Post::whereUserId(auth::id())->get('id')->count();

Dev0ps's avatar

bro, it counts the only post. I wanna count post likes

jdc1898's avatar

Sorry didn't see your second example.

Can you post you schema?

Please or to participate in this conversation.