I have a problem consuming an api, it turns out that when calling it in certain cases it gives me the client and its id because it exists precisely, but in other cases the client simply does not exist, it does not appear in the api data (the client does not appear nor their values).
I have my code as shown in the image, and consequently it throws me that error, what I am trying to do does not work for me, precisely what I am looking for is not to show this ErrorException. This code was from another test in which I used a variable in between, but I didn't get a solution either... I would like to see how to modify it, I tried putting if(array_key_exists(["items"][0]["client"]["id"], $response))
it but it doesn't work for me either
if(array_key_exists("items", $response))
{
$vienedata = $response["items"][0]["client"]["id"];
if ($vienedata !== null)
$this->customerjson = $response["items"][0]["client"]["id"];
}else{
session()->flash('message', 'No existe un registro de cliente');
}
This is the date that in some cases arrives
Instead of this:
For this:
isset() will evaluate whether or not that value exists within the array and you'll skip the error I hope.