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

Aronaman's avatar

Eloquent and tables

3 tables Cash_payment, local_payment, online_payment.

I have daily total price calculated for each table. .my question is its possible to sum total price of 3 tables.

Each table as no relationship and no common table b/c in case of changing value can cause problem .

I think it's clear :)

0 likes
5 replies
Sinnbeck's avatar

I would just run a query for each and sum them afterwards. I cannot see any way to do it in a single query that would effective

itguy614's avatar

I agree w/ Sinnbeck. You could do it all in one query if you wanted to do some subselects. Depending on how often this is used/calculated you may want to consider a SQL view or even a nightly job to do the calculation into a warehouse and then pull your daily off that. It all depends on your final objective.

1 like
Aronaman's avatar

Can you show me with some code please ....I am lost Step by step

Calculation take place every day for all customers

Sinnbeck's avatar

Run ->sum() on each table and the add the results. https://laravel.com/docs/5.8/queries#aggregates

To restrict to a date you can use $q->whereDate('created_at', '=', Carbon::today()->toDateString());

Sorry I am currently on mobile so I am having a hard time formatting properly 😊

1 like
Aronaman's avatar
Aronaman
OP
Best Answer
Level 2

I run sum query for each table and how can I sum the 3 daily price from 3 tables... for specific customer_id, date

Please or to participate in this conversation.