Where 子句不起作用。 Laravel

Where clause not working. Laravel

我正在尝试计算使用多个 where 查询的查询的结果。但它似乎没有用。 我的语法是:

$partialpaidquery=['month' => $maina];

$partialpaid=Bill::where($partialpaidquery)->where('paid','!=',0)->where('fee_status','<','amount')->count();

where 子句最多 where('paid','!=',0) 似乎有效,但第三个无效。这里有什么问题?它实际上应该返回 1。但它返回 0。

您似乎使用了错误的查询: 您正在比较 < 字符串 'amount' 而不是使用变量 $amount

如下所示:

$partialpaidquery=['month' => $maina];

$partialpaid=Bill::where($partialpaidquery)->where('paid','!=',0)->where('fee_status','<',$amount)->count();

使用你的第三个地方作为

->whereRaw('fee_status < amount')

因为您使用它的方式,金额列被解释为字符串而不是列。