遇到Laravel查询生成器的非数字值

问题描述 投票:1回答:3

我有一个正在运行的功能,但是现在突然提示错误。

在HandleExceptions-> handleError(2,'遇到一个非数字值','C:\ xampp \ htdocs \ fdis-laravel \ app \ Receivable.php',67,array('receivable_payment_head_id'=> null,'total_receivable'=>'936.341'))在Receivable.php第67行中]

这是我使用DB:Raw的代码。

<?php

public static function updateLessPaymentHead($receivable_payment_head_id, $total_receivable)
{
    $payment_head = DB::table('receivables_payment_head')
        ->where('id', $receivable_payment_head_id)
        ->update(
            ['total_receivables' => DB::raw('total_receivables' - $total_receivable),
                'total_payment' => DB::raw('total_payment' - $total_receivable),
            ]);

    return $payment_head;
}

有没有一种方法可以解决DB:raw的非数字问题,或者在更新之前需要先将其转换为数字吗?我正在使用Laravel 5.4和PHP 7.1。

我有一个有效的功能,但是现在突然提示错误。在HandleExceptions-> handleError(2,'遇到一个非数字值','C:\ xampp \ htdocs \ fdis-laravel \ app \ Receivable.php',67,...

php laravel laravel-5.4 laravel-query-builder
3个回答
1
投票
您的DB :: raw中存在错误。

0
投票
在您的代码中:'total_receivables' - $total_receivable和此处:'total_payment' - $total_receivable,您正在尝试从字符串中减去数字,这是php 7.1错误。

-1
投票
您需要将其转换为数字格式才能定义函数参数数据类型是这样的
© www.soinside.com 2019 - 2024. All rights reserved.