Skip to content

kenyalang/countries

Repository files navigation

A package to get list of countries

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Installation

You can install the package via composer:

composer require kenyalang/countries

To publish the config file, you can use the following command:

php artisan vendor:publish --provider="\Kenyalang\Countries\CountriesServiceProvider" --tag=config

Usage

Run the migrations to create and populate the countries and states table.

php artisan migrate

By default, the countries will be inactive. To enable them update your .env.

ENABLE_ALL_COUNTRIES=true

To manually enable a country, you may query the desired country and use the activate function.

\Kenyalang\Countries\Models\Country::where('name', 'United States')->activate();

To disable a country, you may query the desired country and use the deactivate function.

\Kenyalang\Countries\Models\Country::where('name', 'United States')->deactivate();

To query only active countries, use the active scope.

\Kenyalang\Countries\Models\Country::active()->get();

Add the following trait to your model to use the countries and states table:

class User extends Model
{
    use \Kenyalang\Countries\Traits\HasCountry;
}

To get the locale of a model use the withLocale scope:

User::withLocale()->first();

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

The list of countries was taken from here. Do check it out.

License

The MIT License (MIT). Please see License File for more information.