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

EckyEckyPtang's avatar

How to add a SUM row to a resource table?

Say you have a column on a resource table with prices. And you want the price total in a new row at the bottom of the table.

What would be the best way to do this?

0 likes
4 replies
Sinnbeck's avatar

You can run sum on the query

MyModel::where('foo', 1)->sum('bar');
Sinnbeck's avatar

Or if it's a relationship you mean

MyModel::where('foo', 1)->withSum('foop', 'bar')->get();

Please or to participate in this conversation.