foreach
我从这样的循环中得到我想要显示的数据
@foreach(auth()->user()->unreadNotifications as $notification)
{{dd($notification->data)}}
{{--{{dd($notification->data['thread']['id'])}}--}}
{{--{{dd($notification->data['thread']['subject'])}}--}}
{{--{{dd($notification->data['user']['name'])}}--}}
@endforeach
所有dd
显示的数据都应该显示没有任何错误,但是当我像这样循环时。
@foreach(auth()->user()->unreadNotifications as $notification)
<a href="{{ropgpute('thread.show',$notification->data['thread']['id'])}}">
{{$notification->data['user']['name']}} commented on <strong> {{$notification->data['thread']['subject']}}</strong>
</a>
@endforeach
它给出了一个错误返回错误:
Undefined index: thread (View: C:\Users\Merlijn\AppData\Roaming\Composer\Laravel Projects\Forum\resources\views\layouts\partials\navbar.blade.php) (View: C:\Users\Merlijn\AppData\Roaming\Composer\Laravel Projects\Forum\resources\views\layouts\partials\navbar.blade.php) (View: C:\Users\Merlijn\AppData\Roaming\Composer\Laravel Projects\Forum\resources\views\layouts\partials\navbar.blade.php)
注意也user
未定义
我不明白为什么dd
工作正常并显示数据,但删除数据的正常foreach
循环没有显示任何内容并返回未定义的索引线程
{{dd($notification->data)}}
输出_
array:2 [▼
"thread" => array:8 [▼
"id" => 1
"subject" => "JSUpdated Updated Updated"
"thread" => "eaeaweaweaewaeawawneaklfnd/waldfwa.fwa"
"type" => "Question Updated"
"created_at" => "2019-03-14 15:34:28"
"updated_at" => "2019-03-14 15:34:38"
"user_id" => 1
"solution" => 2
]
"user" => array:6 [▼
"id" => 1
"name" => "johndoe"
"email" => "johndoe@example.com"
"email_verified_at" => null
"created_at" => "2019-03-14 15:34:15"
"updated_at" => "2019-03-14 15:34:15"
]
]