Here is my code;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies.json",
CURLOPT_HTTPHEADER => array(
"Content-Type: text/plain"
),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET"
));
$response = curl_exec($curl);
curl_close($curl);
$response = json_decode($response, true);
foreach ($response as $code => $name ) {
$currency = new Currency();
$currency->currency_code = $code;
$currency->currency_name = $name;
$save = $currency->save();
}
If I dd($response), it returns all the arrays but when i use foreach loop, it will only save the first value of the array rather than all the values in the array.
This is a repost of the original question.