将Carbon附加到对象属性 - Javascript

时间:2016-08-28 17:49:02

标签: javascript php laravel pusher php-carbon

我现在正在与Pusher合作,当用户发送消息时,我会将其附加到Pusher:

channel.bind('App\\Events\\MessageSent', function(data){
                $('#chat-box-message').empty(html);
                for (var i = 0; i< data.length; i++) {

                    for (var key in data) {  //empty the div for append does not repeat
                        var obj = data[key];
                        for (var prop in obj) {

                            $('#chat-box-message').append(
                                '<div class="comment">'+                                
                                    '<div class="content">'+                                       
                                        '<div class="date">'+
                                            obj[prop]['created_at']+
                                        '</div>'+
                                        '<div class="text">' +
                                            obj[prop]['message']+
                                        '</div>'+
                                     '</div>'+          
                                '</div>'
                            );
                        }
                    }
                }
            });

但我需要补充的是:

<div class="date">
  {{ $message->created_at->diffForHumans() }}
</div>

到此:

  obj[prop]['created_at']+

如何在JavaScript部分的object属性上附加diffForHumans()?

1 个答案:

答案 0 :(得分:0)

正如@Derek所说:

obj[prop]['message'] + '{{ $message->created_at->diffForHumans() }}'