php - 未定义索引 : user when I display notification json array in laravel

标签 php mysql json laravel notifications

当尝试显示 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/

相关文章:

php - MySQL:连接两个表

php - "Unfolding"一个字符串

php - 在没有 Javascript 的 setTimeout() 的数据库条目后刷新页面

java - SQL 语法中的 JDBC 问号

javascript - 如何在JSON.stringify : Uncaught TypeError: Converting circular structure to JSON?中找到循环结构

php - 查询结果回显结果四次

MySQL 子查询 AND 'NOT IN'

PHP生成多个字符串并插入数据库

java - 如何为 Java 8 LocalDateTime 编写自定义序列化器

java - 将 json 文件转换为 sd 卡中存在的字符串