I have post Model which has multiple reactions (Like, dislike etc)
I want to count those reaction by their attr_id. I tried below code and it gives total number of reactions on post.
public function PostReaction() {
return $this->hasMany('App\PostReaction');
}
public function getAttributesCountAttribute() {
return $this->PostReaction()->count();
}
and if I do
return $this->PostReaction()->groupBy('attr_id')->count();
It returns only first reaction count instead of all. It should give array of count with all reactions