Count the votes of an article

Posted 2 months ago by SmokeTM

Hey guys,

wanna count the votes of an article according to an authenticated user. So this means I wanna count all rows where article.id = article_votes.article.id and where the article belongst to the authenticated user.

What I have so far

$articles = Article::WithCount('votes')->with('votes')->where('user_id', auth()->user()->id)->get();

Now $articles has two ids for which I wanna count the rows in my article_votes table, but how can I do that?

Best regards

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.