gpt4 book ai didi

php - 在 Laravel 5 中使用自定义时间戳返回错误

转载 作者:可可西里 更新时间:2023-11-01 00:13:12 25 4
gpt4 key购买 nike

所以在我的迁移中,我添加了一列:

$table->timestamp('due_at');

然后我允许用户为任务设置截止日期,但是当我尝试执行时:

$task->due_at->diffForHumans()

我收到这个错误

Call to a member function diffForHumans() on string

我的自定义时间戳与 created_atupdate_at 的格式完全相同,但它返回错误。

我该怎么做才能解决这个问题?提前谢谢你。

最佳答案

你还需要在模型中声明它,否则 Laravel 不会知道它是一个 Carbon 实例。例如:

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

还有一些文档:https://laravel.com/docs/5.1/eloquent-mutators#date-mutators

关于php - 在 Laravel 5 中使用自定义时间戳返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35777444/

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