发布于 5年前

Call to a member function diffForHumans() on string

前端文章列表页,显示正常

 <div class="ml-1 text-gray-60">
        <small>{{$ac->created_at->diffForHumans()}}</small>
</div>

但在文章内容页

<small class="text-muted">
    发布于 {{ \Carbon\Carbon::parse($created_at)->diffForHumans() }}
</small>

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

解决方案:

由于数据不是Carbon的实例,因此需要先解析它然后再执行diff:

{{ \Carbon\Carbon::parse($created_at)->diffForHumans() }}
©2020 edoou.com   京ICP备16001874号-3