I am currently inserting data from json api url into my database, except some arrays are not completed filled out resulting in 'undefined index' errors.
Is there a good way to deal with this? Ofcourse checking each item index with an if isset statement and only setting it if it is available would work but that would be quite tedious for each entry.
foreach($items['response']['groups'] as $item) {
foreach($item['items'] as $item) {
Bar::firstOrCreate([
'lat' => $item['venue']['location']['lat'],
'long' => $item['venue']['location']['lng'],
'postalCode' => $item['venue']['location']['postalCode'],
'city' => $item['venue']['location']['city'],
'state' => $item['venue']['location']['state'],
'country' => $item['venue']['location']['country'],
'address' => $item['venue']['location']['address'],
'rating' => $item['venue']['rating'],
'website' => $item['venue']['url'],
]);
}
}