将Carbon和Laravel格式化为一行

时间:2016-09-05 09:47:28

标签: php laravel laravel-5.2 php-carbon

我从我的数据库中检索这个日期格式: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?

2 个答案:

答案 0 :(得分:0)

@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

答案 1 :(得分:0)

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

@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