withSum instead of withCount


#1

i use withCount to get the amount of belonging items but how do i get the sum of belonging values is there something like withSum?


#2

Made it work like this, please tell me if there is a better way?

query.leftJoin(
    Database.raw('(select taskhours.customer_id, CAST(sum(taskhours.hour) as float) as totaltaskhours from taskhours where taskhours.deleted_at is null group by taskhours.customer_id) as tth'),
    'id',
    '=',
    'tth.customer_id'
)