Call to a member function toDateTimeString () on null,500 报错跟教程报错不一样?

"message": "Call to a member function toDateTimeString() on null",
"status_code": 500,
"debug": {
    "line": 23,
    "file": "/home/vagrant/Code/larabbs/app/Transformers/TopicTransformer.php",
    "class": "Symfony\\Component\\Debug\\Exception\\FatalThrowableError",
    "trace": [
followyounger
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 6
liyu001989

你需要做的是读一遍报错,具体的原因以及错误的位置都告诉你了,你的 created_at 或者updated_at 是 null

5年前 评论
liyu001989

请不要重复提问

5年前 评论
followyounger

@liyu001989 是的啊,我看报错位置了,我那个回答里面贴上代码了。重复提问的原因,是因为网络不好,提交问题失败,就重复了几次。我created_at那里,我看是没有错的。我上一节是正确的啊,以防万一,我又重新张贴教程的代码,也还是不行

5年前 评论
liyu001989

你的代码是对的,但是数据不对,你看看数据库里面,是不是取出来的数据是null。

或者代码里面判断一下 如果存在再调用 toDateTimeString

5年前 评论
followyounger

@liyu001989 啊啊,好的,忘检查数据库了,谢谢,

5年前 评论

Call to a member function toDateTimeString() on string报错

file

什么情况呢?

Laravel

为什么用now()就可以呢

4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!