Support the ongoing development of Laravel.io →
Eloquent

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

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.