【问题标题】:print notification array in Laravel - Illegal string offsetLaravel 中的打印通知数组 - 非法字符串偏移
【发布时间】:2017-11-01 21:58:13
【问题描述】:


我尝试从通知数组中打印一些数据。 当我在刀片中打印所有数组时:

@foreach ($user->userNotif() as $value)
    {{$value->data}}
@endforeach 

那么一切都很好。结果:

{
    "id": 2,
    "theme": "asdasd"
}

但如果我尝试从此数组中打印“id”:

@foreach ($user->userNotif() as $value)
    {{$value->data['id']}}
@endforeach 

我得到错误:

Illegal string offset 'id'...

帮助!这个数组有什么问题?

【问题讨论】:

    标签: arrays laravel notifications blade


    【解决方案1】:

    我不是 100% 100% 确定,但我相信数据是一个对象,您需要像这样访问 id:

    $value->data->id
    

    作为免责声明,这尚未经过测试。

    希望这会有所帮助!

    【讨论】:

    • nope( 错误:“试图获取非对象的属性”
    • 在你的视图中做 dd($value) 并告诉我它返回什么
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多