How to Subtract Two Integer Values in Different Tables in Laravel

Viewed 1304

I'm trying to achieve subtracting two integer values different tables, this is what I have tried so far.

Controller:
$amount = DB::table('shipping_datas')->where('amount')->first();
$payment = DB::table('payments')->where('amount')->first();
$balance = $amount - $payment;

Blade:
{{ $balance }}

Thank you in advance :)

1 Answers
$amount = DB::table('shipping_datas')->pluck('amount')->sum();
$payment = DB::table('payments')->pluck('amount')->sum();
$balance = $amount - $payment;

i think its work.

Related