我的API
会返回多个帐户objects
,我想在view
中列出,但我不知道如何。
有人能帮助我吗?
方式
public function get(){
$client = new client([
'headers' => ['content-type' => 'application/json' , 'Accept' => 'application/json'],
]);
$response = $client->request('GET','https://lusp.com/api/login');
$data = $response->getBody();
$data = json_decode($data);
dd($data);
}
响应
{#491 ▼
+"accounts": array:2[▼
0 => {#465 ▼
+"id": 7
+"email": "Ivan@mail.com"
+"password": "4154512"
}
1 => {#466 ▼
+"id": 1
+"email": "lucas@mail.com.br.br.br"
+"password": "lucas123"
}
]
}
SF
答案 0 :(得分:1)
dd
不理想,
试着像这样返回它
$data = collect(son_decode($data));
return response()->json($data);
如果您将其返回到视图中,请执行以下操作
$data = collect(json_decode($data));
return View("yourviewname",$data);
和yourviewname.blade.php
@foreach($account as $line)
<span> {{$line->email}} </span>
@endforeach