GithubHelp home page GithubHelp logo

webpatser / laravel-countries Goto Github PK

View Code? Open in Web Editor NEW
735.0 735.0 229.0 519 KB

Laravel Countries is a bundle for Laravel, providing Almost ISO 3166_2, 3166_3, currency, Capital and more for all countries.

License: MIT License

PHP 61.73% Blade 38.27%

laravel-countries's People

Contributors

dmsherazi avatar eigan avatar ferdirn avatar foo99 avatar jpmurray avatar juliangums avatar kevindierkx avatar khaledsmq avatar kitbs avatar lucidlemon avatar mannikj avatar mateusfccp avatar msamec avatar multiwebinc avatar ognjenm avatar paulkned avatar pjona avatar robindirksen1 avatar ryanrapini avatar stewis avatar taftse avatar teeli avatar tsiedsma avatar twmbx avatar watscho avatar webpatser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-countries's Issues

L4.2 installation problem

Just installed your package again, I have installed it many times and it's worked fine, so I think this is a L4.2-related issue.

When generating the migration and seed with: php artisan countries:migration

For some reason the opening <?php tag in both files is coming through like {{ <?php }}.

Cheers for the great package.

Migration timestamps

A small issue, you should add an extra second to the charify_countries_table timestamp to ensure it will be executed only after the main migration; On my system, the timestamps for the two migration files were identical and the charity migration was executed before the countries table was even created.

Thanks.

The CharifyCountriesTable migration doesn't work on SQLite

I'm trying to run my tests using a SQLite database but it fails when it tries to run the CharifyCountriesTable migration with this error:

Doctrine\DBAL\Driver\PDOException: SQLSTATE[HY000]: General error: 1 near "MODIFY": syntax error

Would be interesting + some issues

Would be interesting if you added more methods for list.

For example if i need a method in select field, so that i can get it just by Countries::getForSelect() or by passing which field i want other than fields.

But my issue is bit different, when i dump Countries::getList() i get array with keys and in each array i get a sub array with country data.

But for some idiotic reason if i try to fetch only one field i get that "index" doesn't exist.

looping foreach in foreach, or any other way, simply didn't work.

So i just lost an hour trying to figure it out and it didn't work.

p.s. code in CharifyCountriesTable doesn't work in postgresql!!!

Foreign key constraint

Getting a SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint error on mysql
Should the id for countries not be set as increments ?

New repo based on yours....

Hi Christophe. I needed a Laravel package to install country information and came across yours. I ended up doing a number of edits to it, in part because I wanted to go through the process of putting together a proper Laravel package, and publishing it on Packagist. There were too many edits to submit as pull requests.

So I ended up creating a fresh repo based on your latest codebase. I have credited you prominently in my repo - after all you did all the hard work of getting the info together!

Basically I'm telling you all this out of courtesy, and I hope you don't mind.

Cheers.

Local names

It would be nice to have the local names of each country available:

   "528":{
      ...
      "iso_3166_2":"NL",
      "iso_3166_3":"NLD",
      "name":"Netherlands",
      "local_name":"Nederland",
      "region-code":"150",
      ...
   },

Tag new release

When trying to run php artisan countries:migration this is what is returned..

Method Webpatser\Countries\MigrationCommand::handle() does not exist  

I'm running MySQL and Laravel 5.5

Edit: Seems this was caused because I used the version 1.5.2, when changing to dev-master it resolved itself. Can you tag another proper release? The last release was in January 25th 2017 just about a year ago and it seems there has been lots of changes since.

sizeof(): Parameter must be an array or an object that implements Countable

I am getting this error while seeding the countries

ErrorException: sizeof(): Parameter must be an array or an object that implements Countable in ../../vendor/webpatser/laravel-countries/src/Webpatser/Countries/Countries.php:43

If I remove the sizeof check it works.

//Get the countries from the JSON file
// if (sizeof($this->countries) == 0){
    $this->countries = json_decode(file_get_contents(__DIR__ . '/Models/countries.json'), true);
//}

//Return the countries
return $this->countries;

initializing protected $countries = []; with empty array can fix it.

I am running PHP 7.2

Countries model

If I want to make new eloquent relation, Its in vendor directory.

I think Countries model has to be installed in app directory.

Seeder generation template

Running the generated seeder as is, ended with a PHP Fatal error: Class 'Countries' not found, so to make it work I had to change this:

$countries = Countries::getList();

into:
$model = App::make('countries');
$countries = $model->getList();

Also, imported App at the top:
use Illuminate\Support\Facades\App;

I am using PHP 5.5.12 and Laravel 4.2

'Class countries does not exist'

I updated countries package to 1.3.7 and suddenly I can't get a list of countries any more.

Here's my code

<?php namespace Api;

use Illuminate\Support\Facades\Response;
use Webpatser\Countries\CountriesFacade as Countries;

class CountriesController extends \BaseController
{

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        $countries = Countries::orderBy('name', 'asc')->select('name', 'iso_3166_2 AS code')->get()->toArray();
        return Response::json($countries);
    }

}

And here's a full error log:

[2015-06-23 15:28:27] dev.ERROR: exception 'ReflectionException' with message 'Class countries does not exist' in /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php:504
Stack trace:
#0 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(504): ReflectionClass->__construct('countries')
#1 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(428): Illuminate\Container\Container->build('countries', Array)
#2 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(462): Illuminate\Container\Container->make('countries', Array)
#3 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(806): Illuminate\Foundation\Application->make('countries')
#4 /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(146): Illuminate\Container\Container->offsetGet('countries')
#5 /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(116): Illuminate\Support\Facades\Facade::resolveFacadeInstance('countries')
#6 /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(200): Illuminate\Support\Facades\Facade::getFacadeRoot()
#7 /var/www/html/app/controllers/api/CountriesController.php(16): Illuminate\Support\Facades\Facade::__callStatic('orderBy', Array)
#8 /var/www/html/app/controllers/api/CountriesController.php(16): Webpatser\Countries\CountriesFacade::orderBy('name', 'asc')
#9 [internal function]: Api\CountriesController->index()
#10 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(231): call_user_func_array(Array, Array)
#11 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(93): Illuminate\Routing\Controller->callAction('index', Array)
#12 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(62): Illuminate\Routing\ControllerDispatcher->call(Object(Api\CountriesController), Object(Illuminate\Routing\Route), 'index')
#13 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(967): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'Api\\CountriesCo...', 'index')
#14 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#15 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(109): call_user_func_array(Object(Closure), Array)
#16 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1033): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#17 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1001): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#18 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(775): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#19 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(745): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#20 /var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware.php(72): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)
#21 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Queue.php(47): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)
#22 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Guard.php(51): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)
#23 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)
#24 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(641): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
#25 /var/www/html/public/index.php(49): Illuminate\Foundation\Application->run()
#26 {main} [] []

Why laravel-library and in /libraries?

Hello there,

I've just installed the project and noticed that it's been installed into /libraries.
What is the motivation of having it there instead of usual /vendor ?

Thanks,
Konstantin

Default migration file : countries.id should be unsigned by default

Hi,

Context :

My users table has a country_id column which has a foreign key that references the countries.id column. I had a hard time understanding why I always had the next error while running artisan migrate :

SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL : alter tableusersadd constraint users_country_id_foreign foreign key ( country_id) referencescountries(id))

Explanation :

  • Columns used as a foreign key need to be unsigned as specified in the Laravel docs (hence my users.country_id column type is integer(10) in the database).
  • Though, the default countries.id column is not unsigned in the generated countries migration file (hence its type is integer(11) in the database).
  • Foreign key columns must reference a column of exactly the same type (in MySQL at least, don't really know about other databases) which explains why I got the error.

Solution :

To be able to handle this, I had to change

$table->integer('id')->index();

to

$table->integer('id')->unsigned()->index();

in the generated countries migration file.

Documentation or defaults modification ?

Since using countries.id as a reference for a foreign key looks a pretty common thing to me, I really think there should be some changes about this :

Either adding ->unsigned() to the id column in the default generated migration file or adding a note about this in the readme file ?

I hope this makes sense and I didn't miss something obvious.

This being said, thank you for this bundle which, I'm sure, helped a lot of people (me included).

Add Continent

It would be great, if it could be associated which continent this Country is on (NA, EU...)

Add Kosova as country

Greetings,

I have used laravel-countries for a project of mine but Kosova is missing in the country list.
Kosova is new country and it is possible that some software application has not added it in the list.

You can read about Kosova in Wikidedia:
https://en.wikipedia.org/wiki/Kosovo

Thanks

timezone

Awesome job. I would like to thank you for this project.
And a question:
Are you planning to add timezone of the countries ?

Please add calling codes for each country

You can see from this gist, I've added a country calling code for every country in your database.
The key is the iso_3166_2 code for each country and the value is the country calling code.

https://gist.github.com/lhdev/2b8eeeabe3419ca13bd1

For sake of not editing your package locally, I added this array to the top of the seeder and called it in the seeder like this:

'calling_code' => $this->calling_codes[$country['iso_3166_2']]

First I added this to the migration:
$table->string('calling_code', 3)->nullable();

It would be great if you integrated this going forward!

dump-autoload step needed

Before this step in the installation:

$ php artisan migrate --seed

I needed to do this:

composer.phar dump-autoload

Without this, I get the following error:

-bash-4.1$ php artisan migrate --seed
Nothing to migrate.
  [ReflectionException]
  Class CountriesSeeder does not exist

This is a common issue with Laravel when doing:

php artisan vendor:publish

Migration not work on PostgreSQL

Got this error when using PostgreSQL

syntax error at or near "MODIFY" LINE 1: ALTER TABLE countries MODIFY country_code CHAR(3) NOT NULL D... ^ (SQL: ALTER TABLE

Use CHAR where appropriate

Is there a particular reason why you opted to use the VARCHAR data type for columns that will have
values of identical length?

The columns in question:

  • country_code
  • iso_3166_2
  • iso_3166_3
  • region_code
  • sub_region_code

Changing the columns to CHAR will offer multiple performance improvements and is generally considered a best practice especially if you consider the fact that they are likely to be indexed.

Laravel 5.5 fails to find seeding class

It seems seeding fails in laravel 5.5 when omiting ::class after CountriesSeeder in
/database/seeds/DatabaseSeeder.php.

I suggest changing the README.md to reflect the change.

Region & Subregion Codes Source?

Hello Dear @webpatser
First of all thank you for this awesome package, I've just one question: From where have you obtained countries' region & subregion codes? I'm curios if there's some sort official reference or may be ISO list?

Undefined Index currency

No idea what seems to be wrong ?
@foreach($countries as $country) <option value="{{ $country['country-code'] }}">{{ $country['name'] }}</option> @endforeach

this works fine but when i do the same thing with
`@foreach($countries as $country)

{{ $country['currency'] }} @endforeach`

this doesn't work and it prints out "Undefined Index: currency/currency_code"

Error when updating to 1.4

Exception as follows:

[RuntimeException]
Error Output: PHP Fatal error: Call to undefined method Webpatser\Countries\CountriesServiceProvider::publishes() in /Users/rgvdev1/Documents/workspace/Kepler Workspace/Merchant Dashboard/vendor/webpatser/laravel-countries/src/Webpatser/Countries/CountriesServiceProvider.php on line 29

Model don't consider database table, only json

I noticed that when I migrate the table, and change eg. the id from Afghanistan from 4 to 5, in the rendered list it is still 4, meaning the contents are taken from the json and not from the table... so why do we need a table at all then?

Should the constructor load the JSON every time

Having the ctor load and parse the JSON takes up a large amount of memory and in my current setup I get the following

[11-May-2014 22:20:44 UTC] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in /vagrant/www/vendor/webpatser/laravel-countries/src/Webpatser/Countries/Countries.php on line 30

Using the JSON as the main data source would also mean that in the getList() function if a user added a new country into the database it wouldn't be picked up. The comment for $this->countries also states that it should be a string with the path to the directory containing country data as where the code uses it as an array with all the data.

No commands defined in the "countries" namespace issue

I am using laravel 5.2 (just started learning this framework) and want to use the countries list. I followed the documentation for laravel 5 and when I trying to execute

php artisan countries:migration

I get this error :

[Symfony\Component\Console\Exception\CommandNotFoundException]
There are no commands defined in the "countries" namespace

Can you help me get over this issue?
Thanks a lot

laravel 5 migration refactoring

I wanted to bring it to your attention that your id on the countries table doesn't work with other tables when doing country_id. It needs to use increments instead of integer()->index() and primary(). It throws errors when you try to add foreign key on another table pointing to it otherwise.

PDOException: SQLSTATE[HY000]: General error: 1 near "MODIFY": syntax error

Getting this error:

Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 near "MODIFY": syntax error (SQL: ALTER TABLE countries MODIFY country_code CHAR(3) NOT NULL DEFAULT '')

Since I just installed it in my project, I applied the charifying directly to the countries table and commented the modifications.

5.4

CountriesServiceProvider.php line 72:
Call to undefined method Illuminate\Foundation\Application::share()

Seeding sizeof() Error

When I run php artisan migrate --seed or php artisan db:seed --class=CountriesSeeder, an error show to my terminal and no data inserted into the database:

In Countries.php line 43:
  sizeof(): Parameter must be an array or an object that implements Countable

Fix char migration for pgsql

Hi, it's possible to edit char_migration with this code?
It fix error on postgres for modify function that not exist

public function up()
    {
        Schema::table(\Config::get('countries.table_name'), function ($table) {
            if (env('DB_CONNECTION') == 'pgsql') {
                DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " ALTER COLUMN country_code TYPE CHAR(3)");
                DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " ALTER COLUMN iso_3166_2 TYPE CHAR(2)");
                DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " ALTER COLUMN iso_3166_3 TYPE CHAR(3) ");
                DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " ALTER COLUMN region_code TYPE CHAR(3)");
                DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " ALTER COLUMN sub_region_code TYPE CHAR(3)");
            } else {
                DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " MODIFY country_code CHAR(3) NOT NULL DEFAULT ''");
                DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " MODIFY iso_3166_2 CHAR(2) NOT NULL DEFAULT ''");
                DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " MODIFY iso_3166_3 CHAR(3) NOT NULL DEFAULT ''");
                DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " MODIFY region_code CHAR(3) NOT NULL DEFAULT ''");
                DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " MODIFY sub_region_code CHAR(3) NOT NULL DEFAULT ''");
            }
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return  void
     */
    public function down()
    {
        Schema::table(\Config::get('countries.table_name'), function ($table) {
            if (env('DB_CONNECTION') == 'pgsql') {
                DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " ALTER COLUMN country_code VARCHAR(3) NOT NULL DEFAULT ''");
                DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " ALTER COLUMN iso_3166_2 VARCHAR(2) NOT NULL DEFAULT ''");
                DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " ALTER COLUMN iso_3166_3 VARCHAR(3) NOT NULL DEFAULT ''");
                DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " ALTER COLUMN region_code VARCHAR(3) NOT NULL DEFAULT ''");
                DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " ALTER COLUMN sub_region_code VARCHAR(3) NOT NULL DEFAULT ''");
            } else {
                DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " MODIFY country_code VARCHAR(3) NOT NULL DEFAULT ''");
                DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " MODIFY iso_3166_2 VARCHAR(2) NOT NULL DEFAULT ''");
                DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " MODIFY iso_3166_3 VARCHAR(3) NOT NULL DEFAULT ''");
                DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " MODIFY region_code VARCHAR(3) NOT NULL DEFAULT ''");
                DB::statement("ALTER TABLE " . DB::getTablePrefix() . \Config::get('countries.table_name') . " MODIFY sub_region_code VARCHAR(3) NOT NULL DEFAULT ''");
            }
        });
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.