我PHP
在sonata
框架上的功能出现错误
public function getIsActiveThisYear(): bool
{
$now = Carbon::now();
return $this->whereBetween($endDate, [
Carbon::$now->startOfYear(),
Carbon::$now->endOfYear(),
])|| $this->whereBetween($endDate, [
Carbon::$now->startOfYear(),
Carbon::$now->endOfYear(),
]);
}
这是我测试代码时遇到的错误
错误:调用未定义的方法
您将变量创建$now
为Carbon DateTime,因此Carbon::
在使用它时不需要在其前面。
public function getIsActiveThisYear(): bool
{
$now = Carbon::now();
return $this->whereBetween($endDate, [
$now->startOfYear(),
$now->endOfYear(),
])|| $this->whereBetween($endDate, [
$now->startOfYear(),
$now->endOfYear(),
]);
}
您也使用
$this->whereBetween($endDate,
两次,也许一个应该作为开始日期?但这有点猜测:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句