kenyalang / countries
A package to get list of countries
Requires
- php: ^8.1
- illuminate/contracts: ^9.0
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.8
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2024-11-18 02:37:58 UTC
README
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.