GTHell
354
10
Eloquent

Get top review products?

Posted 1 year ago by GTHell

I have problem with getting the top selling products.

I have 2 tables, products, and product_reviews

  • products(id, name, price)
  • product_reviews(id, product_id, rating)

a product can has many product_reviews

==============================
product
==============================
id |    Name                |         price
----------------------------------------------
1   |    Book .                |         100
2   |    Sock                  |         5000
3   |    Strape               |         9000
==============================
product_reviews
==============================
id | product_id    |    rating
---------------------------------------------
1    |   1                      |     4
2   |   1                      |     5
3   |   2                     |     5
4   |   1                      |     3
5   |   2                     |     4
6   |   1                      |     5
7   |   3                     |     4

As you can see, the product with id 1 probaby has the most review and good review also.

How do I use eloquent to get the result?

Please sign in or create an account to participate in this conversation.