I have stuffs
table where will be saved only stuff title.
Stuffs table:
id
title
Also I've user_stuffs
table where each user has n
stuff volume.
User stuffs table:
id
stuff_id
user_id
volume
How I can SUM
each stuffs volumes and get like this result:
{
"title": "Stuff Title",
"total": 7634
}
I tried using only sql exec like this query but how I can do it correctly in Laravel?
SQL:
SELECT
stuffs.id,
stuffs.title,
SUM(user_stuffs.volume) AS total
FROM `user_stuffs`
INNER JOIN stuffs ON user_stuffs.stuff_id = stuffs.id
GROUP BY user_stuffs.stuff_id