代码之家  ›  专栏  ›  技术社区  ›  John Carlo

类的对象carbon\carbon无法转换为int laravel

  •  0
  • John Carlo  · 技术社区  · 5 年前

    如果计划已过期,我如何实现,其中我想返回状态“match will start soon”。

    代码如下:

     @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
    

    但没用。有什么想法吗?

    0 回复  |  直到 5 年前
        1
  •  2
  •   piscator    5 年前

    你好像想把一个碳实例和int 0 . 这会导致异常:

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

    你可以通过比较它来检查时间表是否在过去。

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