一尘不染

Laravel:如何在视图刀片中解析此json数据?

json

目前这是我的看法

{{ $leads }}

这是输出

{"error":false,"member":[{"id":"1","firstName":"first","lastName":"last","phoneNumber":"0987654321","email":"email@yahoo.com","owner":{
"id":"10","firstName":"first","lastName":"last"}}]}

我想展示这样的东西

Member ID: 1
Firstname: First
Lastname: Last
Phone: 0987654321

Owner ID: 10
Firstname: First 
Lastname: Last

阅读 268

收藏
2020-07-27

共1个答案

一尘不染

很简单 首先将解码后的变量发送到视图(请参见Laravel Views):

view('your-view')->with('leads', json_decode($leads, true));

然后只需使用常见的刀片构造(请参见Laravel模板制作)

@foreach($leads['member'] as $member)
    Member ID: {{ $member['id'] }}
    Firstname: {{ $member['firstName'] }}
    Lastname: {{ $member['lastName'] }}
    Phone: {{ $member['phoneNumber'] }}

    Owner ID: {{ $member['owner']['id'] }}
    Firstname: {{ $member['owner']['firstName'] }} 
    Lastname: {{ $member['owner']['lastName'] }}
@endforeach
2020-07-27