marshmallow/dataset-country
Composer 安装命令:
composer require marshmallow/dataset-country
包简介
This dataset contains all the countries in the world. They are translateable in different languages. It is also possible to get the flag from said countries. The model is extendable so you can extend and overide all functionality if needed.
关键字:
README 文档
README
Marshmallow Dataset Country
This dataset contains all the countries in the world. They are translateable in different languages. It is also possible to get the flag from said countries. The model is extendable so you can extend and override all functionality if needed.
Installation
Install the package via Composer:
composer require marshmallow/dataset-country
The service provider is auto-discovered and the package migrations are loaded automatically, so you only need to run your migrations:
php artisan migrate
This creates a countries table with name, slug, alpha2 and alpha3 columns (each unique).
Seed the table
Run the bundled seeder to fill the countries table:
php artisan db:seed --class="Marshmallow\Datasets\Country\Seeders\CountrySeeder"
Publish the flags
To use the flag images you need to publish them to your local project:
php artisan vendor:publish --provider="Marshmallow\Datasets\Country\ServiceProvider" --tag=public --force
You can optionally publish the translations as well:
php artisan vendor:publish --provider="Marshmallow\Datasets\Country\ServiceProvider" --tag=translations
Usage
The package ships an Eloquent model at Marshmallow\Datasets\Country\Models\Country.
use Marshmallow\Datasets\Country\Models\Country; // Look up a country by its ISO alpha-2 code. $country = Country::alpha2('nl'); // Get all countries ordered by name. $countries = Country::ordered()->get();
Methods
- Get the locale (translated) version of a country name with
$country->getNameLocale().
Flags
You can get the flag of a country with $country->flag. If you wish to specify the size of the flag image, you can use $country->flag(16). The available sizes are 16, 24, 32, 48, 64 and 128 (the default is 32). Remember to publish the flags first (see Installation).
Traits
Add the Marshmallow\Datasets\Country\Traits\HasCountry trait to your models that have a country. This sets up the country() relationship:
use Marshmallow\Datasets\Country\Traits\HasCountry; class Address extends Model { use HasCountry; } // $address->country instanceof Country
Nova
Are you using Nova? We have a command for you to generate the Nova Resource. Run php artisan marshmallow:resource Country Datasets\\Country and countries will be available to you in Nova. We hide this resource by default in the Nova navigation. If you wish to have it available in the navigation, add public static $displayInNavigation = true; to app/Nova/Country.php.
Provinces, cities and airports
The model also exposes a provinces() relationship. This requires the optional marshmallow/dataset-google-geotargets package, which provides Google data on provinces, cities, airports etc.
composer require marshmallow/dataset-google-geotargets
Translations
The country names are translated into the following languages:
- Arabic (ar)
- Chinese (cn)
- Czech (cs)
- Danish (da)
- German (de)
- Greek (el)
- English (en)
- Spanish (es)
- Estonian (et)
- French (fr)
- Hungarian (hu)
- Italian (it)
- Japanese (ja)
- Lithuanian (lt)
- Dutch (nl)
- Norwegian (no)
- Polish (pl)
- Portuguese (pt)
- Romanian (ro)
- Russian (ru)
- Slovak (sk)
- Thai (th)
- Ukrainian (uk)
Security Vulnerabilities
Please report security vulnerabilities by email to stef@marshmallow.dev rather than via the public issue tracker.
Credits
License
The MIT License (MIT). Please see the License File for more information.
Copyright (c) 2020 marshmallow
marshmallow/dataset-country 适用场景与选型建议
marshmallow/dataset-country 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.98k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 04 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「marshmallow」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 marshmallow/dataset-country 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 marshmallow/dataset-country 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 marshmallow/dataset-country 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This packages provides you with the ability to easily connect your Laravel application to ZohoDesk.
Generate slugs when saving Eloquent models
A Laravel Nova help field.
Connect your Kiyoh to your Laravel application
Sending request to you Google Analytics has never been easier. With support for e-commerce tracking.
A package to simply add metadata to models
统计信息
- 总下载量: 8.98k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 24
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-07