gpt4 book ai didi

php - 错误 : Call to a member function addDays() on string

转载 作者:行者123 更新时间:2023-12-05 08:15:28 39 4
gpt4 key购买 nike

我想在指定日期添加天数。这是我的代码:

if (Carbon::now() <= $campaign->s_lastrun->addDays(28)) {
$onAir = 1;
}

它一直有效,直到我对我的数据库做了一些更改,现在我收到一个错误:Call to a member function addDays() on string even though s_lastrun has列类型 DATE。有什么想法吗?

最佳答案

您需要告诉 Eloquent 这是一个日期,以便它会将其转换为 Carbon。根据 docs :

By default, Eloquent will convert the created_at and updated_at columns to instances of Carbon, which extends the PHP DateTime class to provide an assortment of helpful methods. You may customize which dates are automatically mutated, and even completely disable this mutation, by overriding the $dates property of your model.

因此在您的模型中,添加以下内容:

protected $dates = ['created_at', 'updated_at', 's_lastrun'];

如果您不使用默认时间戳,请删除 created_atupdated_at

关于php - 错误 : Call to a member function addDays() on string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45062103/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com