我已创建通知以将订单提交事件存储为
return [
'cart_id'=>$this->cart->id,
'text'=>'order is submitted'
];
当我从数据库中检索通知数据时
@foreach (Auth::user()->unreadNotifications as $notification )
{{$notification->data['text'] }}
@endforeach
这会将错误作为未定义的索引文本
但是如果我尝试通过以下方式访问文本
@foreach ($notification->data as $key => $data)
{{$data}}
@endforeach
它有效
但是为什么我不能通过$notification->data['text']
访问数据
你应该直接获取text
属性,如下所示:
@foreach (Auth::user()->unreadNotifications as $notification )
{{ $notification->text }}
//Or use
{{ $notification['text'] }}
@endforeach
希望这有帮助。