【问题标题】:How to Subtract Two Integer Values in Different Tables in Laravel如何在 Laravel 的不同表中减去两个整数值
【发布时间】:2020-11-27 12:19:32
【问题描述】:

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

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

Blade:
{{ $balance }}

提前谢谢你:)

【问题讨论】:

  • 虽然您的要求不是很清楚,但我认为您的两个变量($amount 和 $payment)都查询同一个表: DB::table('shipping')->where ('金额');
  • 有什么问题?得不到结果?在代码中的 2 个表中相同。您没有在查询后添加->first()。您无法获得结果。
  • 好的,谢谢您的回复,请稍候
  • 两者都相同DB::table('shipping')->where('amount'); 实际上问题不清楚。请您进一步澄清一下,您要达到的目标是什么?
  • ->where('amount')->first(); 但是您的系统如何知道哪一行?可能你错过了->where('amount', 100)->where('id', 1)

标签: php mysql laravel


【解决方案1】:
$amount = DB::table('shipping_datas')->pluck('amount')->sum();
$payment = DB::table('payments')->pluck('amount')->sum();
$balance = $amount - $payment;

我认为它的工作。

【讨论】:

    猜你喜欢
    • 2019-05-02
    • 2015-02-06
    • 2019-09-20
    • 1970-01-01
    • 1970-01-01
    • 2021-08-12
    • 1970-01-01
    • 1970-01-01
    • 2016-07-28
    相关资源
    最近更新 更多