laravel-country.io maintained by anandpilania
anandpilania/laravel-country.io
UPDATE (v2.0.4)
-
Your own
migrationname, -
Set model from config,
-
Performance improvement.
-
v2.0.3
- KEEP needed columns only,
- direct control via
configfile.
Laravel-Country.io - artisan based package that can fetch countries list with details aka:
- Code
- Continent
- Capital
- GDP
- Population
- ISO2/3
- Language
- Population
and more directly from Country.io and store it directly into file|db.
Installation
$ composer require anandpilania/laravel-country.io
FIRST STEP
$ php artisan vendor:publish --tag=countryio-config
and configure config according to your need.
OPTIONAL STEP
$ php artisan vendor:publish --tag=countryio-migration
BEFORE USING
Configure/adjust countryio config file according to your need
- table_name - table name for storing in DB,
- model - Define your own `Model` class [\App\Models\Country::class],
- cols_type - `plain|json` [`plain` aka `continent`, `population_total` AND `json` aka `geography.continent`, `population.total`],
- cols - `cols_type` free columns,
- cols_plain|json - `cols_type` based columns,
- file - If not DB, than location of file (`--to=file|db` option of `countryio` artisan command)
How to use
First take a look of supported options
$ php artisan help countryio
--to : file OR db
--offline : save fetched files to `storage/country` dir
--clean : clean everything after setup
--fresh : Fresh install (for `db` use only, truncates)
--silent : silent work
NOTE: Default location is storage/app/countryio.json
So, if you want to file list only (default):
First publish the config file
$ php artisan vendor:publish --tag="countryio-config"
then, change the location: config/countryio.php
'file' => storage_path('app/...');
and fire:
php artisan countryio
FOR db:
anandpilania/laravel-country.io contains Country migration & model
php artisan countryio --to=db
will create migration table (based on countryio config) & CountryIO model (DEFAULT, if not set in config file) & update the database directly.
Why not using migration publish: beacuse if your application already have migration/model for country then ...
Todos
- App use
filebasedtable - Flags
Play with artisan:
Add to routes/console.php:
Artisan::command('countries', function () {
$count = $this->ask('How many entries?');
$model = config('countryio.model', \App\Models\CountryIO::class);
if(!class_exists($model)) {
$this->error($model . ' not exists!');
}
foreach ((new $model)->take($count ?? 10)->get() as $c) {
$output = '';
foreach (array_merge(config('countryio.cols', []), config('countryio.cols_' . config('countryio.cols_type', 'plain'), [])) as $col => $enabled) {
if ($enabled) {
$output .= $c->{$col} . ', ';
}
}
$this->comment($output);
}
})->purpose('Check CountryIO');
and php artisan countries :)
License
MIT
Free Software, Hell Yeah!