我有一个代码,如果一个数组不是空的话应该运行但由于某种原因,它仍然会运行,即使它是空的。这就是我所拥有的:
$fifteenDays = Carbon::today('America/Los_Angeles')->subDays(15);
$invoiceSent = Invoice::whereDate('invoiceDue', '<=',$fifteenDays)->where('isPaid', 0)->where('isPaying', 0)->get();
if (!empty($invoiceSent)) {
//Run Code In here
}
无论$invoiceSent
是否为空,都会运行。
答案 0 :(得分:0)
get()
方法返回Collection
Countable
。
这导致empty
实际上是真的,而count()
将返回0.这是违反直觉的,但仍然是语言特定的功能。