kenyalang / countries
获取国家列表的包
v1.1.0
2022-07-15 15:33 UTC
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-09-18 02:21:50 UTC
README
安装
您可以通过 composer 安装此包
composer require kenyalang/countries
要发布 config
文件,您可以使用以下命令
php artisan vendor:publish --provider="\Kenyalang\Countries\CountriesServiceProvider" --tag=config
用法
运行迁移以创建和填充 countries
和 states
表。
php artisan migrate
默认情况下,countries
将处于非活动状态。要启用它们,请更新您的 .env
。
ENABLE_ALL_COUNTRIES=true
要手动启用一个国家,您可以查询所需的国家并使用 activate
函数。
\Kenyalang\Countries\Models\Country::where('name', 'United States')->activate();
要禁用一个国家,您可以查询所需的国家并使用 deactivate
函数。
\Kenyalang\Countries\Models\Country::where('name', 'United States')->deactivate();
要查询仅活跃国家,请使用 active
范围。
\Kenyalang\Countries\Models\Country::active()->get();
将以下特性添加到您的模型中,以使用 countries
和 states
表
class User extends Model { use \Kenyalang\Countries\Traits\HasCountry; }
要获取模型的区域设置,请使用 withLocale
范围
User::withLocale()->first();
测试
composer test
变更日志
请参阅 CHANGELOG 了解最近更改的详细信息。
致谢
国家列表来自 这里。请查看。
许可
MIT 许可证 (MIT)。请参阅 许可文件 了解更多信息。