Call to a member function diffForHumans()on string

自定义 timestamp 字段,报错

创建数据库的时候,加了一个时间的字段

$table->timestamp('last_reply_actived_at')->nullable()->comment('最后回复的时间');

最后 在transformer 转出的时候,想转换成 5分钟前 这种方法

一般的 created_at 可以利用

$posts->created_at->diffForHumans()

即可~

但是 这个不行... 报错

Call to a member function diffForHumans() on string

解决方法

use Carbon\Carbon;

'lastReplyActived' => isset($posts->last_reply_actived_at) ? Carbon::parse($posts->last_reply_actived_at)->diffForHumans() : null,


欢迎转载,但请附上原文地址哦,尊重原创,谢谢大家 本文地址: http://www.iphpt.com/detail/95/

当你能力不能满足你的野心的时候,你就该沉下心来学习