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

Overview

Laravel Countries

Total Downloads Latest Stable Version Latest Unstable Version

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.

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

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

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

    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

    opened by saqueib 19
  • Seeding sizeof() Error

    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
    
    opened by sandofvega 6
  • Error when updating to 1.4

    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

    opened by russellraed 5
  • Use singleton method to register commands

    Use singleton method to register commands

    In Laravel 5.4 the share method has been removed from the container.

    opened by henry-spanka 4
  •  Method Webpatser\Countries\MigrationCommand::handle() does not exist

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

    When i run php artisan countries:migration i get Method Webpatser\Countries\MigrationCommand::handle() does not exist on the console i'm using Laravel 5.5

    opened by GMounir 4
  • Region & Subregion Codes Source?

    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?

    opened by Omranic 3
  • PHP Parse error:  syntax error, unexpected '[' in ... /src/commands/MigrationCommand.php on line 94

    PHP Parse error: syntax error, unexpected '[' in ... /src/commands/MigrationCommand.php on line 94

    Hi I have this error in composer after update to the latest version:

    PHP Parse error: syntax error, unexpected '[' in ... /src/commands/MigrationCommand.php on line 94

    $migrationFiles is supposed to be an array, isn't it ? I can send you a pull request, but maybe it's easy for you to solve it directly.... Whatever you want.

    Thank you for the bundle anyway :)

    Best regards

    opened by tx2z 3
  • timezone

    timezone

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

    opened by burhanturkce 3
  • Use CHAR where appropriate

    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.

    opened by nCrazed 3
  •   Your configuration files are not serializable.

    Your configuration files are not serializable.

    Launching this "php artisan countries:migration" in a terminal window I get following: Your configuration files are not serializable.

    no closures in my config files

    opened by giojkd 0
  • Update countries.json

    Update countries.json

    Brexit: Set eea of GB to false

    opened by MannikJ 0
  • Fix creation of Countries Seeder for Laravel >= 8

    Fix creation of Countries Seeder for Laravel >= 8

    Laravel 8 change the directory name for seeders from seeds to seeders

    opened by adrianbarnes 3
  • fix override Eloquent model constructor

    fix override Eloquent model constructor

    This will cause error when we use

    $factory->define(\Webpatser\Countries\Countries::class, function (Faker $faker) {
        return [
            'id'                => 458,
            'capital'           => 'Kuala Lumpur (MY1)',
            'citizenship'       => 'Malaysian',
            'country_code'      => 458,
            'currency'          => 'ringgit (inv.)',
            'currency_code'     => 'MYR',
            'currency_sub_unit' => 'sen (inv.)',
            'currency_decimals' => '2',
            'full_name'         => 'Malaysia',
            'iso_3166_2'        => 'MY',
            'iso_3166_3'        => 'MYS',
            'name'              => 'Malaysia',
            'region_code'       => '142',
            'sub_region_code'   => '035',
            'eea'               => 0,
            'calling_code'      => '60',
            'currency_symbol'   => 'RM',
            'flag'              => 'MY.png',
        ];
    });
    
    $country = factory(\Webpatser\Countries\Countries::class)->create();
    dd($country);
    

    The result will have missing attributes

    Webpatser\Countries\Countries^ {#1014
      #countries: []
      #table: "countries"
      #connection: "mysql"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: true
      #attributes: array:1 [
        "id" => 0
      ]
      #original: array:1 [
        "id" => 0
      ]
      #changes: []
      #casts: []
      #classCastCache: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: []
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #fillable: []
      #guarded: array:1 [
        0 => "*"
      ]
    }
    
    opened by jslim89 0
  • Support for Laravel 8 - Unable to open CountriesSeeder.php

    Support for Laravel 8 - Unable to open CountriesSeeder.php

    Since Laravel8, seeders have been moved to database/seeders See here: https://laravel.com/docs/8.x/seeding

    However currently the migration creation file tries to create the seeder at: $seeder_file = $this->laravel->path."/../database/seeds/CountriesSeeder.php";

    So this is failing with the error:

      fopen(../database/seeds/CountriesSeeder.php): failed to open stream: No such file or directory
    
      at vendor/webpatser/laravel-countries/src/commands/MigrationCommand.php:119
    
    opened by hildaaaa 3
  • Country England not in the list why?

    Country England not in the list why?

    I found that UK is listed as country and the countries like England and Scotland are not present in the json. Is there a reason to? England is a country.

    opened by diogopalhais 1
  • update autoload section

    update autoload section

    make autoload section composer 2.x compatible and remove warning during installation in composer ^1.10 fixes #115

    opened by restuff 0
  • Deprecation notice for Composer v2.0: not-autoloading

    Deprecation notice for Composer v2.0: not-autoloading

    Seeing deprecation notice:

      - Installing webpatser/laravel-countries (1.5.4): Downloading (100%)
    Generating optimized autoload files
    Deprecation Notice: Class Webpatser\Countries\MigrationCommand located in ./vendor/webpatser/laravel-countries/src/commands/MigrationCommand.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///usr/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:185
    
    opened by mblarsen 0
  • Update countries.json

    Update countries.json

    • Updated Philippines currency_symbol value
    opened by adromil 1
Owner
Christoph Kempen
Specializes in building high performance APIs with Laravel/Lumen and Elasticsearch.
Christoph Kempen
GeoLocation-Package - This package helps you to know the current language of the user, the country from which he is browsing, the currency of his country, and also whether he is using it vpn

GeoLocation in PHP (API) ?? ?? ?? This package helps you to know a lot of information about the current user by his ip address ?? ?? ?? This package h

Abdullah Karam 3 Dec 27, 2021
Tiny Laravel worldwide currency formatter

Laravel Currency Formatter Tiny Laravel worldwide currency formatter Install composer require magarrent/laravel-currency-formatter Usage use Magarrent

Marc Garcia Torrent 11 Oct 13, 2021
A simple Laravel Package to sort Countries, States and Cities

Laravel Location ▲ Introduction ?? This Package offers a simple way to get Countries, Cities and States that you may need for your Application, most e

Michael Okoh 184 Jan 12, 2022
Laravel countries and currencies

Countries What does it gives you? This package has all sorts of information about countries: info items taxes 32 geometry maps 248 topology maps 248 c

Antonio Carlos Ribeiro 1.6k Jan 2, 2022
A package that uses blade templates to control how markdown is converted to HTML inside Laravel, as well as providing support for markdown files to Laravel views.

Install Install via composer. $ composer require olliecodes/laravel-etched-blade Once installed you'll want to publish the config. $ php artisan vendo

Ollie Codes 19 Jul 5, 2021
A simple drop-in solution for providing UUID support for the IDs of your Eloquent models.

Introduction A simple drop-in solution for providing UUID support for the IDs of your Eloquent models. Both v1 and v4 IDs are supported out of the box

GoldSpec Digital 438 Jan 11, 2022
Laravel Twitter Bootstrap Bundle

Bootstrapper Latest stable version: Travis status : Current supported Bootstrap version: 3.2.0 Bootstrapper is a set of classes that allow you to quic

Patrick Talmadge 568 Jan 12, 2022
Laravel Livewire (TALL-stack) form generator with realtime validation, file uploads, array fields, blade form input components and more.

TALL-stack form generator Laravel Livewire, Tailwind forms with auto-generated views. Support Contributions Features This is not an admin panel genera

TinaH 547 Jan 14, 2022
Links statistics & link tracking for laravel 5, It tracks down browsers, operating systems, languages and more

Links Links statistics for laravel 5 Table Of Contents Installation Configuration Usage Installation To install charts use composer Download composer

Erik C. Forés 52 Jul 31, 2021
A quiz application with laravel 8, spatie permissions, livewire, jetstream, chartjs, tailwindcss and more!

Todo Currently busy with some other important things, will definately would like to imporove the app with 1. Multiple choices selection and mapping to

Baig 35 Jan 4, 2022
Manage your staff from one place. Featuring Staff leave management 🏖, payslips 💵 generation & emailing, messaging 📨and more 🛠! Built with ❤️ with Laravel

Staff Management System This little buddy can help you manage your staff database! Built with ?? with Laravel #FEATURES 1 Staff management/ database S

Ezekiel Oladejo 37 Dec 28, 2021
🕵️ Inspect Laravel Eloquent models to collect properties, relationships and more.

??️ Eloquent Inspector Inspect Laravel Eloquent models to collect properties, relationships and more. Install Via Composer composer require cerbero/el

Andrea Marco Sartori 13 Jan 18, 2022
webtrees module: enhanced clippings cart with more functions to add records to the clippings cart and to start actions on these records

webtrees module hh_clippings_cart_enhanced !!! This is an alpha version! Do not use it in a productive webtrees system! !!! This webtrees custom modul

Hermann Hartenthaler 1 Dec 3, 2021
a Laravel package help you to execute more effective databases queries.

Laravel Query Helper Laravel Query Helper was developed for laravel 7.2+ to help you optimizing sql queries, this package will contain all advanced sq

karam mustafa 8 Dec 16, 2021
Laravel 5 Repositories is used to abstract the data layer, making our application more flexible to maintain.

Laravel 5 Repositories is used to abstract the data layer, making our application more flexible to maintain.

Anderson Andrade 3.9k Jan 11, 2022
A package for more Laravel commands.

Lara-Commands A package for more Laravel commands. Installation This package can be installed via Composer: composer require nimaw/lara-commands --dev

Nima 7 Jan 9, 2022
The list of all Algerian provinces and cities according to the official division in different formats: csv, xlsx, php, json, etc.

algeria-cities This repository contains the list of all the administrative provinces and cities in Algeria. The data is up-to-date according to the of

Ramtani Othmane 304 Jan 5, 2022
This package provides new helper functions that take care of handling all the translation hassle and do it for you.

Laravel Translate Message ?? This package provides new helper functions that take care of handling all the translation hassle and do it for you. Insta

Basel Rabia 1 Jan 7, 2022
Add variables to the payload of all jobs in a Laravel app

Inject extra info to the payloads of all jobs in a Laravel app This package makes it easy to inject things in every job. Imagine that you want to have

Spatie 48 Jan 8, 2022