nnjeim / world

A Laravel package which provides a list of the countries, states, cities, currencies, timezones and languages.
MIT License
748 stars 105 forks source link

Ability to migrate only some countries and also to append others later #25

Closed aeq-dev closed 2 years ago

aeq-dev commented 2 years ago

Is your feature request related to a problem? Please describe. No

Describe the solution you'd like Sometimes we may need only some countries for our application, so no need to insert the whole World DB, and later we may append other countries

Thanks

aeq-dev commented 2 years ago

You can set a parameter 'loadedCountries' in world config : 'loadedCountries' => ['US', 'FR'], and in initCountries function, something like this:


private function initCountries(): void
    {
        app(Models\Country::class)->truncate();
        $this->countries['data'] = json_decode(File::get(__DIR__ . '/../../resources/json/countries.json'), true);
        if (!empty(config('world.loadedCountries')))
            $this->countries['data'] = Arr::where($this->countries['data'], function ($value, $key) {
                return in_array($value['iso2'], config('world.loadedCountries'));
            });

```}

I've done a PR for this. 
Please check :)