【发布时间】:2019-09-15 23:52:15
【问题描述】:
我正在尝试将 JSON 响应从控制器传递到视图,但 JSON 数组已更改。 当我从 Api 获取时,如何传递 JSON 数组。
控制器代码:
$client = new Client();
$response = $client->request('GET', env('API_URL').'/profile_question', [
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Bearer '.$accessToken,
],
])->getBody();
$response = json_decode($response);
return view('account/incomplete_profile', compact(['response']));
dd 导致控制器:
{#273 ▼
+"swingstatus": array:3 [▶]
+"searchingfor": []
+"language": []
+"headline": []
+"description": []
+"lookingfor": []
+"birthday": []
+"eyes": []
+"haircolor": []
+"height": []
+"weight": []
+"bodytype": []
+"raceethnics": []
+"smokes": []
+"piercings": []
+"tattoos": []
+"sexuality": []
+"hasexperience": []
+"looksareimportant": []
+"integlligence": []
+"hairlength": []
+"bodyhair": []
+"comfortlevel": []
+"whatdoyoulike": []
+"fetish": []
}
从视图中删除:
array:3 [▼
0 => {#284 ▶}
1 => {#289 ▶}
2 => {#287 ▶}
]
谁能帮我在不改变的情况下在我的视图中获取 Api 输出?
【问题讨论】: