Пример #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('currencies')->delete();
     $currencies = json_decode(file_get_contents('https://openexchangerates.org/api/currencies.json?app_id=74e989a64ee04c2283c3f3a7ca631d1d'));
     $commonCurrencies = array_keys(PunicCurrency::getAllCurrencies(false, false, 'en'));
     $locales = Config::get('translatable.locales');
     foreach ($currencies as $code => $name) {
         $currency = ['code' => $code, 'is_used' => in_array($code, $commonCurrencies)];
         foreach ($locales as $key => $locale) {
             if (is_array($locale)) {
                 $currency[$key] = ['name' => PunicCurrency::getName($code, null, $key)];
                 foreach ($locale as $countryLocale) {
                     if (($name = PunicCurrency::getName($code, null, $key . '-' . $countryLocale)) != $currency[$key]['name']) {
                         $currency[$key . '-' . $countryLocale] = ['name' => $name];
                     }
                 }
             } else {
                 $currencyName = PunicCurrency::getName($code, null, $locale);
                 if ($currencyName || $locale == 'en') {
                     $currency[$locale] = ['name' => $currencyName ?: $name];
                 }
             }
         }
         Currency::create($currency);
     }
     $extras = ['GGP' => '根西岛镑', 'JEP' => '泽西岛镑', 'IMP' => '马恩岛镑', 'BTC' => '比特币'];
     foreach ($extras as $code => $name) {
         if ($currency = Currency::whereCode($code)->first()) {
             $currency->fill(['zh-Hans' => ['name' => $name]]);
             $currency->save();
         }
     }
 }
Пример #2
0
 private function getDropdowns()
 {
     $countries = Country::withTranslation()->whereIsActive()->orderByTranslation('sortas')->get()->lists('name', 'id');
     $languages = Language::orderBy('name')->get()->lists('name', 'id');
     $currencies = Currency::withTranslation()->orderByTranslation('sortas')->get()->lists('name', 'id');
     view()->share('countries', $countries);
     view()->share('languages', $languages);
     view()->share('currencies', $currencies);
 }
Пример #3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('users')->delete();
     $users = [['id' => 1, 'name' => 'System', 'email' => 'system@vinfo', 'password' => bcrypt('password'), 'is_admin' => true], ['id' => 2, 'name' => 'Admin', 'email' => 'admin@vinfo', 'password' => bcrypt('password'), 'is_admin' => true], ['id' => 3, 'name' => 'User', 'email' => 'user@vinfo', 'password' => bcrypt('password'), 'is_admin' => false]];
     $country = Country::whereCode('GB')->first();
     $language = Language::whereCode('en-GB')->first();
     $currency = Currency::whereCode('GBP')->first();
     foreach ($users as $userData) {
         $user = new User();
         $user->fill($userData);
         $user->country()->associate($country);
         $user->language()->associate($language);
         $user->currency()->associate($currency);
         $user->save();
     }
 }
Пример #4
0
 public function languageAndCurrencyByCountry($id)
 {
     $country = Country::find($id);
     if ($country) {
         $code = $country->code;
         $languages = PunicTerritory::getLanguages($code, 'of', true);
         $languages = array_map(function ($value) {
             return str_replace('_', '-', $value);
         }, $languages);
         $allLanguages = Language::lists('code')->toArray();
         $languages = array_intersect(array_merge((array) $languages, ['en']), $allLanguages);
         $language = head($languages);
         $allCurrencies = Currency::lists('code')->toArray();
         $currencies = PunicCurrency::getCurrencyForTerritory($code);
         $currencies = array_intersect(array_merge((array) $currencies, ['GBP']), $allCurrencies);
         $currency = head($currencies);
         $language = Language::whereCode($language)->first();
         $currency = Currency::whereCode($currency)->first();
         return ['language_id' => $language->id, 'currency_id' => $currency->id];
     } else {
         return response('error', 404);
     }
 }
Пример #5
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $currency = Currency::findOrFail($id);
     $this->authorize('destroy', $currency);
     if ($currency->delete()) {
         return redirect(action('CurrenciesController@index'))->with('success', trans('messages.deleted_success'));
     }
     return redirect(action('CurrenciesController@edit', $currency->id))->with('error', trans('messages.deleted_error'));
 }