未定义的索引:当我在 laravel 中显示通知 json 数组时的用户
Posted
技术标签:
【中文标题】未定义的索引:当我在 laravel 中显示通知 json 数组时的用户【英文标题】:Undefined index: user when I display notification json array in laravel 【发布时间】:2017-12-10 19:41:53 【问题描述】:当尝试显示 json 数据时,它会给出未定义的索引:用户异常
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'])" />
$notifications->data['user']['email'] commented on your post.
<span class="pull-right text-muted small">$notifications->created_at->diffForHumans()</span>
</div>
Json 对象是
"comment":"comment":"我很棒","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"
【问题讨论】:
【参考方案1】:查看您的代码后,我假设您正在对集合使用 foreach 循环。
<div>
<i class="fa fa-comment fa-fw"></i>
<img src="url('images/account/'.$notifications->user->currentimage" />
$notifications->user->email commented on your post.
<span class="pull-right text-muted small">$notifications->created_at->diffForHumans()</span>
【讨论】:
以上是关于未定义的索引:当我在 laravel 中显示通知 json 数组时的用户的主要内容,如果未能解决你的问题,请参考以下文章
使用新模型和保护的 Laravel 身份验证失败:未定义索引:模型
想要在 mysql 查询中求和时收到“未定义索引”通知[重复]