public static function storeData($data) { $date = $data['date']; unset($data['date']); if (!empty($data)) { foreach ($data as $tempdata) { $dbcurrency = Currency::where('currency_name', $tempdata['currency'])->get(); if (empty($dbcurrency->all())) { $newcurrency = new Currency(); $newcurrency->currency_name = $tempdata['currency']; $newcurrency->save(); } $currencyid = Currency::where('currency_name', $tempdata['currency'])->first()->id; $search = ['date' => $date, 'currency_id' => $currencyid]; $dbvalues = Value::where($search)->get(); if (empty($dbvalues->all())) { $newvalue = new Value(); $newvalue->currency_id = $currencyid; $newvalue->value = $tempdata['value']; $newvalue->date = $date; $newvalue->save(); } } } else { $search = ['date' => $date, 'currency_id' => '0']; $dbvalues = Value::where($search)->get(); if (empty($dbvalues->all())) { $newvalue = new Value(); $newvalue->currency_id = '0'; $newvalue->value = '0'; $newvalue->date = $date; $newvalue->save(); } } }
public function getRates() { $api_url = Config::get("forex.api_url"); $api_key = Config::get("forex.api_key"); $currencies = Config::get("forex.currencies"); // Initialize CURL: $ch = curl_init($api_url . '=' . $api_key . '¤cies=' . $currencies . '&source=&format=1'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Store the data: $json = curl_exec($ch); curl_close($ch); // Decode JSON response: $exchangeRates = json_decode($json, true); if ($exchangeRates['success']) { foreach ($exchangeRates['quotes'] as $code => $rate) { Currency::where('code', $code)->update(['rate' => $rate]); } } else { echo "Error getting Rates"; dd($exchangeRates); } }
/** * Run the database seeds. * * @return void */ public function run() { $usd = \App\Currency::where('name', 'USD')->first(); $user = \App\User::where('email', '*****@*****.**')->first(); \App\BankAccount::firstOrCreate(['amount' => 0, 'user_id' => $user->getKey(), 'currency_id' => $usd->getKey()]); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $deleteChecked = Input::get('list'); if ($deleteChecked) { foreach ($deleteChecked as $delete) { $resumdel1 = Currency::where('id', $delete)->delete(); } Session::flash('message', 'Successfully deleted'); } else { } return Redirect::to('currency'); }