overtrue/laravel-vote

Why total votes are returned as an absolute value?

gordanielyan opened this issue · 4 comments

For example if there are more downvotes shouldn't it return a negative value?

return abs($this->attributes['total_votes'] ?? $this->totalVotes());

@gordanielyan I don't think so, it means "How many users voted" or "How many votes were cast in total", not "upvotes - downvotes"

@overtrue but why is it sum then?

return abs($this->votes()->sum('votes'));

if you have 3 downvotes and one upvote it returns 2, is it right result?

Sorry, I went through the source code again, you are right, this project has not been updated for too long, after just reading it carefully, I confirmed that the abs here should be redundant, it may be a problem caused by copying the code at first, I'll fix it, thanks again for your feedback.