【问题标题】:Can't set Carbon date to null in Laravel 5无法在 Laravel 5 中将 Carbon 日期设置为空
【发布时间】:2016-01-13 10:04:00
【问题描述】:

我的迁移中有一个列 dateTime,Laravel 假定它为 Carbon。列名是terminado_em,可以为空。

我已经使用我的模型设置了Carbon 值。

现在当我想将terminado_em 设置为null

public function reiniciar()
{
    $this->terminado_em = null;
    ...
}

我得到了错误

InvalidArgumentException in Carbon.php line 425: Data missing

Carbon 属性已经设置为 Carbon 值时,如何将其设置为 null?

【问题讨论】:

    标签: php datetime model laravel-5.1


    【解决方案1】:

    我无法设置对象 Carbon 属性直接访问属性 $this->terminado_em,但访问通用模型 attributes 属性它起作用了。

    $this->attributes['terminado_em'] = null;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-30
      • 2015-09-28
      • 1970-01-01
      • 2018-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多