I have three tables:
products: id|name|description|slug|category_id|...
reviews: id|product_id|review_text|name|email|...
review_rows id|review_id|criteria|rating
the overview table is stored in the overview table, the author of the review and has the foreign key product_id. The review_rows table stores ratings for various criteria, such as:
----------------------------------------
| id | criteria | rating | review_id |
----------------------------------------
| 1 | price | 9 | 12 |
----------------------------------------
| 2 | service | 8 | 12 |
----------------------------------------
| 3 | price | 6 | 54 |
----------------------------------------
| 4 | service | 10 | 54 |
----------------------------------------
Review Lineslinked to the browse table with the foreign key review_id. I established my model relationship as follows:
Product -> hasMany -> Review
Review -> belongsTo -> Product
Review -> hasMany -> ReviewRow
ReviewRow -> belongsTo -> Review
Now I would like to display the average product rating on my category and product page. How can I achieve this?
I need to summarize and average all review reviews per view, and then summarize and average all of them for each review in order to get an overall rating for this product. Is this possible via Eloquent or do I need another solution or another database design / structure?
Thanks in advance!