gpt4 book ai didi

php - Laravel中如何将不同表中的两个整数值相减

转载 作者:行者123 更新时间:2023-12-04 17:26:08 24 4
gpt4 key购买 nike

我正在尝试在不同的表中减去两个整数值,这是我迄今为止尝试过的。

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

Blade:
{{ $balance }}
先感谢您 :)

最佳答案

$amount = DB::table('shipping_datas')->pluck('amount')->sum();
$payment = DB::table('payments')->pluck('amount')->sum();
$balance = $amount - $payment;
我认为它的工作。

关于php - Laravel中如何将不同表中的两个整数值相减,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63297091/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com