未定义索引:用户在laravel中显示通知json数组时

时间:2017-07-06 17:01:00

标签: php mysql json laravel notifications

当尝试显示json数据时,它会提供Undefined index:user exception

  foreach(auth()->user()->unreadnotifications as $notifications)

       @include('frontend.common.notification.'.snake_case(class_basename($notifications->type)))

  @endforeach

包含的视图代码是

  <div>
    <i class="fa fa-comment fa-fw"></i>
    <img src="{{url('images/account/'.$notifications->data['user']['currentimage'])}}" height="50px" width="50"/>
    {{$notifications->data['user']['email']}} commented on your post.
    <span class="pull-right text-muted small">{{$notifications->created_at->diffForHumans()}}</span>
</div>

Json对象

  

{&#34;评论&#34;:{&#34;评论&#34;:&#34;我很棒&#34;,&#34; user_id&#34;:2,&#34; post_id& #34;:&#34; 2&#34;,&#34; commment_rate&#34;:90,&#34; updated_at&#34;:&#34; 2017-07-06 16:32:07&#34; ,&#34; created_at&#34;:&#34; 2017-07-06 16:32:07&#34;,&#34; id&#34;:18},&#34; user&#34;:{ &#34; ID&#34;:2&#34;电子邮件&#34;:&#34; test2@mail.com",&#34; currentimage&#34;:&#34; 1499004938.jpg&# 34;,&#34;作用&#34;:0,&#34;验证&#34;:空,&#34;封端的&#34;:空,&#34; created_at&#34;:&#34; 2017年-07-02 13:44:24&#34;,&#34; updated_at&#34;:&#34; 2017-07-02 14:15:38&#34;}}

1 个答案:

答案 0 :(得分:0)

在查看代码后,我假设您在集合中使用了foreach循环。

setInterval(function(){
    googletag.pubads().refresh(null, {changeCorrelator: false});
}, 30000);