Reputation: 91
My API
returns several account objects
, I would like to list it in my view
, but I do not know how.
Can someone help me?
Method
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);
}
Response
{#491 ▼
+"accounts": array:2[▼
0 => {#465 ▼
+"id": 7
+"email": "[email protected]"
+"password": "4154512"
}
1 => {#466 ▼
+"id": 1
+"email": "[email protected]"
+"password": "lucas123"
}
]
}
sf
Upvotes: 0
Views: 778
Reputation: 2523
dd
is not ideal to return,
try to return it like this
$data = collect(son_decode($data));
return response()->json($data);
if you're returning it into a view, do it like the following
$data = collect(json_decode($data));
return View("yourviewname",$data);
and in yourviewname.blade.php
@foreach($account as $line)
<span> {{$line->email}} </span>
@endforeach
Upvotes: 1