Level 75
You want to rework the query to use relations, and not use a GROUP BY? You would need to setup the relations, run migrations, etc. Or use query builder, the ORM also has query builder built in.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I want to convert this SQL query to an eloquent query :
SELECT round(AVG(rating.reviews),2) as avg_rating, COUNT(excursions.id) as review_total, excursions.name FROM reviews LEFT JOIN excursions ON reviews.excursion_id = excursions.id GROUP BY excursion_id
Please or to participate in this conversation.