【问题标题】:Object of class Carbon\Carbon could not be converted to int LARAVELCarbon\Carbon 类的对象无法转换为 int LARAVEL
【发布时间】:2019-02-26 16:22:12
【问题描述】:

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

代码如下:

 @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】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2017-05-18
      • 2015-10-01
      • 1970-01-01
      • 2017-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-03
      • 2018-10-27
      相关资源
      最近更新 更多