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

denizgolbas's avatar

Run query WithSum() for sub Withsum()'s result

User::where('id', 1)->withSum(['descendants' => function($query) { return $query->whereDepth('<', 10)->depthFirst()->withSum('nfts', 'price'); }],'nfts_sum_price')->first();

I'm trying to withsum() inside other withsum's results. When I try just sum id it works. But i need sum of ->withSum('nfts', 'price') this method what returns. I take "Undefined column" error.

Is it possible for to sum like that in 1 query? And how I do it?

0 likes
0 replies

Please or to participate in this conversation.