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

Comments
  • 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
  •  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
  • Add support for ISO 639

    Add support for ISO 639

    I think it may be worthwhile to support ISO 639 language codes and maybe match them to country codes. I think geonames does it https://github.com/ipalaus/geonames/wiki http://download.geonames.org/export/dump/countryInfo.txt

    opened by yurtesen 3
  • 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
  • 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
  • Should the constructor load the JSON every time

    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.

    opened by EspadaV8 3
  • Fix error

    Fix error

    In certain random times I am having the following error:

    sizeof(): Parameter must be an array or an object that implements Countable```
    
    This fixes this issue by setting the value also when `$this->countries` is unset|null
    opened by DrowningElysium 2
  • Fix: PHP 7.2 E_WARNING about sizeof()

    Fix: PHP 7.2 E_WARNING about sizeof()

    As PHP 7.2, an E_WARNING will be emitted when attempting to count() non-countable types (this includes the sizeof() alias function). [source]

    Since null is a non-countable type, trying to use this bundle with bleeding PHP will throw a error when seeding database.

    This pull request closes issue https://github.com/webpatser/laravel-countries/issues/79.

    opened by mateusfccp 2
  • Seeders folder instead seeds

    Seeders folder instead seeds

    I found an issue with the countries:migration laravel command excecution. I have fixed it chanching the seeds forder for seeders folder name. In the /vendor/webpatser/laravel-countries/src/commands/MigrationCommand.php

    $seeder_file = $this->laravel->path."/../database/seeders/CountriesSeeder.php";

    I think this could be a laravel version case. but is easy to fix it.

    Thxs!

    opened by sebastian-sulbaran 0
  • Your code require an update in MigrationCommand

    Your code require an update in MigrationCommand

    The path to the CountriesSeeders in webpatser/laravel-countries/src/MigrationCommand on line 119 is obsolete. Please change $seeder_file = $this->laravel->path."/../database/seeds/CountriesSeeder.php"to $seeder_file = $this->laravel->path."/../database/seeders/CountriesSeeder.php"

    opened by Darklight096 0
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 4 Dec 8, 2022
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 17 Oct 5, 2022
Check Exchange Rates for any currency in Laravel.

Exchange Check exchange rates for any currency in Laravel If your app supports multi-currency, you'll no doubt need to check exchange rates. There are

Worksome 94 Oct 9, 2022
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 197 Jan 1, 2023
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.7k Dec 29, 2022
Countries for Laravel

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

Antonio Carlos Ribeiro 140 Jan 5, 2023
Library for getting countries info from restcountries.com

librestcountries Library for getting countries info from restcountries.com Description Library for getting countries info from restcountries.com Getti

null 4 Sep 18, 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
Providing some testing functionality for Laravel

Laravel TestBench Laravel TestBench was created by, and is maintained by Graham Campbell, and provides some testing functionality for Laravel. It util

Graham Campbell 50 Dec 20, 2022
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 501 Jan 4, 2023
The query filter bundle allows you to filter data from QueryBuilder and the Database.

The query filter bundle allows you to filter data from QueryBuilder and the Database. you can filter multiple columns at the same time and also you can filter relation fields with two-level deep and without any join in your query builder.

Bugloos 15 Dec 29, 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 563 Nov 30, 2022
Symfony bundle that provides Cross Site Request Forgery (CSRF or XSRF) protection for client-side applications

CSRF Cookie Bundle This Symfony bundle provides Cross Site Request Forgery (CSRF or XSRF) protection for client-side applications requesting endpoints

David Neustadt 8 Nov 28, 2022
Log executed Laravel SQL queries and their line number and more

A lightweight laravel package for logging executed SQL queries, line number and more

Md.Harun-Ur-Rashid 31 Dec 21, 2022
Laravel Setting - Easily save, update and get titles, descriptions, and more. it is very easy to use.

Laravel Setting Easily save, update and get titles, descriptions, and more. it is very easy to use. This is great for storing and receiving general si

Ali Ranjbar 2 Aug 23, 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 622 Jan 2, 2023
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 67 Nov 21, 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 45 Jan 3, 2023