danimohamadnejad's avatar

how to get all ratings for specific category?

Hello

I want to be able to access all the ratings of a category in ecommerce application. here are tables and models:

Category

categories -->>id name

Product

products -->>id name

ProductCategory

product_categories-->> id product_id category_id

Rating

ratings-->>id product_id user_id score

I am using following method in Category model:

public function ratings(){

return $this->hasManyThrough('App\Rating','App\ProductCategory','category_id','product_id','id','id');

}

I have only one category and all the ratings are given to products of that category. but using above method not all rows return from database. is above method correct?

please help

0 likes
1 reply

Please or to participate in this conversation.