定制 marshmallow/dataset-country 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

alt text

Marshmallow Dataset Country

Latest Version on Packagist Total Downloads

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

统计信息

  • 总下载量: 8.98k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 11
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固