user13423237
user13423237

Reputation:

How to Subtract Two Integer Values in Different Tables in Laravel

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 :)

Upvotes: 5

Views: 2582

Answers (1)

Moolchand Sharma
Moolchand Sharma

Reputation: 198

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

i think its work.

Upvotes: 3

Related Questions