当尝试显示 json 数据时,它给出了 undefined index :用户异常
foreach(auth()->user()->unreadnotifications as $notifications)
@include('frontend.common.notification.'.snake_case(class_basename($notifications->type)))
@endforeach
包含的 View 代码是
<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 对象是
{"comment":{"comment":"I am awesome","user_id":2,"post_id":"2","commment_rate":90,"updated_at":"2017-07-06 16:32:07","created_at":"2017-07-06 16:32:07","id":18},"user":{"id":2,"email":"test2@mail.com","currentimage":"1499004938.jpg","role":0,"verified":null,"blocked":null,"created_at":"2017-07-02 13:44:24","updated_at":"2017-07-02 14:15:38"}}
最佳答案
查看您的代码后,我假设您正在集合上使用 foreach 循环。
<div>
<i class="fa fa-comment fa-fw"></i>
<img src="{{url('images/account/'.$notifications->user->currentimage}}" height="50px" width="50"/>
{{$notifications->user->email}} commented on your post.
<span class="pull-right text-muted small">{{$notifications->created_at->diffForHumans()}}</span>
关于php - 未定义索引 : user when I display notification json array in laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44955001/