Carbon \ Carbon类的对象无法转换为int LARAVEL

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

如果计划已经过期,我该如何实施?我希望返回状态“匹配即将开始”。

这是代码:

 @if($match->schedule > 0)
      &nbsp;<strong id="match_schedule">Match will start soon</strong>
 @endif

我试过了 :

@if($match->schedule > $match->schedule)
      &nbsp;<strong id="match_schedule">Match will start soon</strong>
@endif

但它不起作用。有任何想法吗?

laravel-5 php-carbon
1个回答
2
投票

您似乎正在尝试将Carbon实例与int 0进行比较。这会导致异常:

Carbon \ Carbon类的对象无法转换为int。

您可以通过比较它来检查计划是否在过去:

@if($match->schedule < Carbon\Carbon::now())
    &nbsp;<strong id="match_schedule">Match will start soon</strong>
@endif
© www.soinside.com 2019 - 2024. All rights reserved.