首页 > 解决方案 > Carbon\Carbon 类的对象无法转换为 int LARAVEL

问题描述

如果时间表已过期,我该如何实施,我想在哪里返回“比赛将很快开始”的状态。

这是代码:

 @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-5php-carbon

解决方案


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

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

您可以通过这样的比较来检查时间表是否在过去:

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

推荐阅读