/** * Bootstrap the application services. */ public function boot() { parent::boot(); $this->publishMigrations(); $app = $this->app; if ($app->bound('form')) { $app->form->macro('selectCountry', function ($name, $selected = null, $options = []) use($app) { $countries = Cache::rememberForever('brianfaust.countries.select.name.cca2', function () { $records = Country::get(['name', 'cca2']); $countries = new Collection(); $records->map(function ($item) use(&$countries) { $countries[$item['cca2']] = $item['name']['official']; }); return $countries->sort(); }); return $app->form->select($name, $countries, $selected, $options); }); $app->form->macro('selectCountryWithId', function ($name, $selected = null, $options = []) use($app) { $countries = Cache::rememberForever('brianfaust.countries.select.id.cca2', function () { $records = Country::get(['name', 'id']); $countries = new Collection(); $records->map(function ($item) use(&$countries) { $countries[$item['id']] = $item['name']['official']; }); return $countries->sort(); }); return $app->form->select($name, $countries, $selected, $options); }); } }
public function fire() { DB::table('countries')->delete(); $data = base_path('vendor/mledoze/countries/dist/countries.json'); $data = json_decode(file_get_contents($data), true); foreach ($data as $country) { Country::create($country); } $this->getOutput()->writeln('<info>Seeded:</info> Countries'); }
public static function boot() { parent::boot(); static::saving(function ($address) { if (config('addressable.geocode')) { $address->geocode(); } if (empty($address->country_id)) { $defaultCountry = config('addressable.default_country'); $country = Country::where('cca2', '=', $defaultCountry)->first(['id']); $address->country_id = $country->id; } }); }