Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Belio's avatar
Level 18

Using Metrics with relations

Is there a way to sum relations in Trends? I have an accessor in my Invoice model that goes through the Lines in order to get the total but I can't use eloquent here as far as I know.

Any ideas?

0 likes
3 replies
AntLusher's avatar

Anyone sorted this. I need to do a sum on two different resources/tables.

So sum a column in one table, then use the result against another column in a different table

muzafferdede's avatar

i end up use like so for one of my metrics. you can use eloquent. i was defining as SaleItem::class but then i changed it and now i could filter out with the way i want. you can also use with() method to eager load your relations


return $this->count($request, SaleItem::where('salable_type', Token::class)->with('salable'), 'salable_id', 'token_type')->label(function ($value) {
            return  $value . ' Token';
        });

Please or to participate in this conversation.