vendor and env first commit
@@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Christoph Kempen
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1,55 @@
|
||||
# Laravel Countries
|
||||
|
||||
[](https://packagist.org/packages/webpatser/laravel-countries)
|
||||
[](https://packagist.org/packages/webpatser/laravel-countries)
|
||||
[](https://packagist.org/packages/webpatser/laravel-countries)
|
||||
|
||||
Laravel Countries is a bundle for Laravel, providing Almost ISO 3166_2, 3166_3, currency, Capital and more for all countries.
|
||||
|
||||
**Please note that version 1.4 is Laravel 5 only, older versions of Laravel should use version 1.3.4 instead**
|
||||
|
||||
## Installation
|
||||
|
||||
Add `webpatser/laravel-countries` to `composer.json`.
|
||||
|
||||
"webpatser/laravel-countries": "dev-master"
|
||||
|
||||
Run `composer update` to pull down the latest version of Country List.
|
||||
|
||||
**If you're using Laravel 5.5, you don't have to edit `app/config/app.php`.**
|
||||
|
||||
Edit `app/config/app.php` and add the `provider` and `filter`
|
||||
|
||||
'providers' => [
|
||||
'Webpatser\Countries\CountriesServiceProvider',
|
||||
]
|
||||
|
||||
Now add the alias.
|
||||
|
||||
'aliases' => [
|
||||
'Countries' => 'Webpatser\Countries\CountriesFacade',
|
||||
]
|
||||
|
||||
|
||||
## Model
|
||||
|
||||
You can start by publishing the configuration. This is an optional step, it contains the table name and does not need to be altered. If the default name `countries` suits you, leave it. Otherwise run the following command
|
||||
|
||||
$ php artisan vendor:publish
|
||||
|
||||
Next generate the migration file:
|
||||
|
||||
$ php artisan countries:migration
|
||||
$ composer dump-autoload
|
||||
|
||||
It will generate the `<timestamp>_setup_countries_table.php` migration and the `CountriesSeeder.php` seeder. To make sure the data is seeded insert the following code in the `seeds/DatabaseSeeder.php`
|
||||
|
||||
//Seed the countries
|
||||
$this->call('CountriesSeeder');
|
||||
$this->command->info('Seeded the countries!');
|
||||
|
||||
You may now run it with the artisan migrate command:
|
||||
|
||||
$ php artisan migrate --seed
|
||||
|
||||
After running this command the filled countries table will be available
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"name" : "webpatser/laravel-countries",
|
||||
"description" : "Laravel Countries is a bundle for Laravel, providing Almost ISO 3166_2, 3166_3, currency, Capital and more for all countries.",
|
||||
"authors" : [{
|
||||
"name" : "Christoph Kempen",
|
||||
"email" : "christoph@downsized.nl",
|
||||
"homepage" : "http://downsized.nl/",
|
||||
"role" : "developer"
|
||||
}, {
|
||||
"name" : "Paul Kievits",
|
||||
"role" : "developer"
|
||||
}
|
||||
],
|
||||
"keywords" : [
|
||||
"laravel",
|
||||
"countries",
|
||||
"iso_3166_2",
|
||||
"iso_3166_3"
|
||||
],
|
||||
"homepage" : "https://github.com/webpatser/laravel-countries",
|
||||
"license" : [
|
||||
"MIT"
|
||||
],
|
||||
"require" : {
|
||||
"php" : ">=5.3.0"
|
||||
},
|
||||
"autoload" : {
|
||||
"psr-0" : {
|
||||
"Webpatser\\Countries" : "src/"
|
||||
},
|
||||
"classmap" : [
|
||||
"src/commands"
|
||||
]
|
||||
},
|
||||
"minimum-stability" : "dev",
|
||||
"support" : {
|
||||
"source" : "https://github.com/webpatser/laravel-countries",
|
||||
"issues" : "https://github.com/webpatser/laravel-countries/issues"
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Webpatser\\Countries\\CountriesServiceProvider"
|
||||
],
|
||||
"aliases": {
|
||||
"Countries": "Webpatser\\Countries\\CountriesFacade"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace Webpatser\Countries;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* CountryList
|
||||
*
|
||||
*/
|
||||
class Countries extends Model {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* Path to the directory containing countries data.
|
||||
*/
|
||||
protected $countries;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* The table for the countries in the database, is "countries" by default.
|
||||
*/
|
||||
protected $table;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->table = \Config::get('countries.table_name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the countries from the JSON file, if it hasn't already been loaded.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getCountries()
|
||||
{
|
||||
//Get the countries from the JSON file
|
||||
if (! $this->countries){
|
||||
$this->countries = json_decode(file_get_contents(__DIR__ . '/Models/countries.json'), true);
|
||||
}
|
||||
|
||||
//Return the countries
|
||||
return $this->countries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns one country
|
||||
*
|
||||
* @param string $id The country id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOne($id)
|
||||
{
|
||||
$countries = $this->getCountries();
|
||||
return $countries[$id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of countries
|
||||
*
|
||||
* @param string sort
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getList($sort = null)
|
||||
{
|
||||
//Get the countries list
|
||||
$countries = $this->getCountries();
|
||||
|
||||
//Sorting
|
||||
$validSorts = [
|
||||
'capital',
|
||||
'citizenship',
|
||||
'country-code',
|
||||
'currency',
|
||||
'currency_code',
|
||||
'currency_sub_unit',
|
||||
'full_name',
|
||||
'iso_3166_2',
|
||||
'iso_3166_3',
|
||||
'name',
|
||||
'region-code',
|
||||
'sub-region-code',
|
||||
'eea',
|
||||
'calling_code',
|
||||
'currency_symbol',
|
||||
'flag',
|
||||
];
|
||||
|
||||
if (!is_null($sort) && in_array($sort, $validSorts)){
|
||||
uasort($countries, function($a, $b) use ($sort) {
|
||||
if (!isset($a[$sort]) && !isset($b[$sort])){
|
||||
return 0;
|
||||
} elseif (!isset($a[$sort])){
|
||||
return -1;
|
||||
} elseif (!isset($b[$sort])){
|
||||
return 1;
|
||||
} else {
|
||||
return strcasecmp($a[$sort], $b[$sort]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//Return the countries
|
||||
return $countries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of countries suitable to use with a select element in Laravelcollective\html
|
||||
* Will show the value and sort by the column specified in the display attribute
|
||||
*
|
||||
* @param string display
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getListForSelect($display = 'name')
|
||||
{
|
||||
foreach ($this->getList($display) as $key => $value) {
|
||||
$countries[$key] = $value[$display];
|
||||
}
|
||||
|
||||
//return the array
|
||||
return $countries;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Webpatser\Countries;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
* CountriesFacade
|
||||
*
|
||||
*/
|
||||
class CountriesFacade extends Facade {
|
||||
|
||||
/**
|
||||
* Get the registered name of the component.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor() { return 'countries'; }
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Webpatser\Countries;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
/**
|
||||
* CountryListServiceProvider
|
||||
*/
|
||||
class CountriesServiceProvider extends ServiceProvider {
|
||||
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
|
||||
/**
|
||||
* Bootstrap the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public function boot()
|
||||
{
|
||||
// The publication files to publish
|
||||
$this->publishes([__DIR__ . '/../../config/config.php' => config_path('countries.php')]);
|
||||
|
||||
// Append the country settings
|
||||
$this->mergeConfigFrom(
|
||||
__DIR__ . '/../../config/config.php', 'countries'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register everything.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->registerCountries();
|
||||
$this->registerCommands();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerCountries()
|
||||
{
|
||||
$this->app->bind('countries', function($app)
|
||||
{
|
||||
return new Countries();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the artisan commands.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerCommands()
|
||||
{
|
||||
$this->app->singleton('command.countries.migration', function ($app) {
|
||||
return new MigrationCommand($app);
|
||||
});
|
||||
|
||||
$this->commands('command.countries.migration');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return ['countries'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace Webpatser\Countries;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class MigrationCommand extends Command {
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'countries:migration';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Creates a migration following the Laravel-countries specifications.';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$app = app();
|
||||
$app['view']->addNamespace('countries',substr(__DIR__,0,-8).'views');
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$this->line('');
|
||||
$this->info('The migration process will create a migration file and a seeder for the countries list');
|
||||
|
||||
$this->line('');
|
||||
|
||||
if ( $this->confirm("Proceed with the migration creation? [Yes|no]") )
|
||||
{
|
||||
$this->line('');
|
||||
|
||||
$this->info( "Creating migration and seeder..." );
|
||||
if( $this->createMigration( 'countries' ) )
|
||||
{
|
||||
$this->line('');
|
||||
|
||||
if (version_compare(app()->version(), '5.5.0', '<')) {
|
||||
$this->call('optimize', []);
|
||||
}
|
||||
|
||||
$this->line('');
|
||||
|
||||
$this->info( "Migration successfully created!" );
|
||||
}
|
||||
else{
|
||||
$this->error(
|
||||
"Coudn't create migration.\n Check the write permissions".
|
||||
" within the app/database/migrations directory."
|
||||
);
|
||||
}
|
||||
|
||||
$this->line('');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias fire method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->fire();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the migration
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
protected function createMigration()
|
||||
{
|
||||
//Create the migration
|
||||
$app = app();
|
||||
$migrationFiles = [
|
||||
$this->laravel->path."/../database/migrations/*_setup_countries_table.php" => 'countries::generators.migration',
|
||||
$this->laravel->path."/../database/migrations/*_charify_countries_table.php" => 'countries::generators.char_migration',
|
||||
];
|
||||
|
||||
$seconds = 0;
|
||||
|
||||
foreach ($migrationFiles as $migrationFile => $outputFile) {
|
||||
if (sizeof(glob($migrationFile)) == 0) {
|
||||
$migrationFile = str_replace('*', date('Y_m_d_His', strtotime('+' . $seconds . ' seconds')), $migrationFile);
|
||||
|
||||
$fs = fopen($migrationFile, 'x');
|
||||
if ($fs) {
|
||||
$output = "<?php\n\n" .$app['view']->make($outputFile)->with('table', 'countries')->render();
|
||||
|
||||
fwrite($fs, $output);
|
||||
fclose($fs);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
$seconds++;
|
||||
}
|
||||
}
|
||||
|
||||
//Create the seeder
|
||||
$seeder_file = $this->laravel->path."/../database/seeds/CountriesSeeder.php";
|
||||
$output = "<?php\n\n" .$app['view']->make('countries::generators.seeder')->render();
|
||||
|
||||
if (!file_exists( $seeder_file )) {
|
||||
$fs = fopen($seeder_file, 'x');
|
||||
if ($fs) {
|
||||
fwrite($fs, $output);
|
||||
fclose($fs);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Database settings
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The name of the table to create in the database
|
||||
|
|
||||
*/
|
||||
'table_name' => 'countries',
|
||||
];
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1010 B |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1005 B |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1016 B |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 968 B |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 971 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 959 B |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1018 B |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 957 B |
|
After Width: | Height: | Size: 962 B |
|
After Width: | Height: | Size: 973 B |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 950 B |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 994 B |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 954 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 958 B |
|
After Width: | Height: | Size: 959 B |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 2.1 KiB |