Using Guzzle I am hooking into an API. The API will provide me with a valid JSON object that contains values I require. I have tried several methods to retrieve an array of values located within the response but at this point can only get one per request via the number of the row:
Here is my current code:
public function index () {
//$value = "07332927917462,07332927917455";
$client = new Client();
$response = $client->get('https://example.com/xxx',
[ 'query' => [
'secret' => '2acbefghijklmnop',
'created' => '2016-01-01']]);
$data = json_decode($response->getBody()->getContents());
$array = $data->products;
$collect = collect($array);
$unique = $collect->unique('ean');
$unique->values()->all();
return dd($unique[0]->ean);
}
In my return dd($unique[0]->ean);
I am receiving only one EAN value (via the number), so it will look like this;
"012345678910"
When I try to call it using return dd($unique->ean);
I receive an error:
Bascially, what I need to do is get all the rows, not just one. so the request would be something like (for example purposes) return dd($unique[all]->ean);
but I am not sure how to approach this?
Any help would be greatly appreciated.
Here is my response using just dd($unique);
: