Created
June 13, 2017 02:49
-
-
Save arungpisyadi/698710c47a21f6d8109ffdb986739365 to your computer and use it in GitHub Desktop.
openexchange.org using laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function updateCurrencies() | |
{ | |
$listed = DB::table('currencies')->get(); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_URL, 'https://openexchangerates.org/api/latest.json?app_id=9dfc90f4fd60462d9088aa0039ccb30d&base=USD'); | |
$result = curl_exec($ch); | |
curl_close($ch); | |
$obj = json_decode($result); | |
// echo $result->access_token; | |
$rates = $obj->rates; | |
foreach($listed as $curr){ | |
$_curr = $curr->code; | |
$rate = $rates->$_curr; | |
$updated_at = date("Y-m-d H:i:s"); | |
DB::table('currencies') | |
->where('id', $curr->id) | |
->update(['updatedAt' => $updated_at, 'rate' => $rate]); | |
echo "$_curr updated to $rate at $updated_at \n\n"; | |
} | |
echo "Updating currencies finished"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment