格式日期与碳和Laravel在一行


Format date with Carbon and Laravel in one line

我从数据库中检索到以下日期格式:2016-09-05T10:24:13Z

我需要得到这个日期,并直接应用diffForHumans()碳方法。

我有一个票消息聊天时间轴:

@foreach($ticket->messages as $msg)
  <div class="chat-bubble>
    <div class="chat-msg">{{ $msg->message }}</div>
    <div class="chat-footer">{{ $msg->creation_date }}</div> //here needs carbon diff
  </div>
@endforeach

如何在一个代码行中使用我的tickets.blade.php中的Carbon ?

@foreach($ticket->messages as $msg)
  <div class="chat-bubble>
    <div class="chat-msg">{{ $msg->message }}</div>
    <div class="chat-footer">{{ $msg->creation_date->diffForHumans() }}</div> //here needs carbon diff
  </div>
@endforeach

你应该这样写。希望这能解决你的问题

@foreach($ticket->messages as $msg)
  <div class="chat-bubble>
    <div class="chat-msg">{{ $msg->message }}</div>
    <div class="chat-footer">{{ $msg->creation_date->diffForHumans() }}</div> 
  </div>
@endforeach