cuitcode/laravel-countries

Laravel Countries 是一个为 Laravel 提供的包,为所有国家提供几乎完整的 ISO 3166_2、3166_3、货币、首都等信息。

1.5.4 2018-05-16 06:37 UTC

This package is auto-updated.

Last update: 2024-09-27 17:04:48 UTC


README

Total Downloads Latest Stable Version Latest Unstable Version

Laravel Countries 是一个为 Laravel 提供的包,为所有国家提供几乎完整的 ISO 3166_2、3166_3、货币、首都等信息。

请注意,版本 1.4 仅适用于 Laravel 5,Laravel 5 的旧版本应使用版本 1.3.4。

安装

cuitcode/laravel-countries 添加到 composer.json

"cuitcode/laravel-countries": "dev-master"

运行 composer update 以拉取最新的国家列表版本。

编辑 app/config/app.php 并添加 providerfilter

'providers' => [
    'Cuitcode\Countries\CountriesServiceProvider',
]

现在添加别名。

'aliases' => [
    'Countries' => 'Cuitcode\Countries\CountriesFacade',
]

模型

您可以首先发布配置。这是一个可选步骤,它包含表名,不需要更改。如果默认名称 countries 适合您,则保留它。否则,运行以下命令

$ php artisan vendor:publish

接下来生成迁移文件

$ php artisan countries:migration

它将生成 <timestamp>_setup_countries_table.php 迁移文件和 CountriesSeeder.php 种子文件。要确保数据被种植,在 seeds/DatabaseSeeder.php 中插入以下代码

//Seed the countries
$this->call('CountriesSeeder');
$this->command->info('Seeded the countries!'); 

现在可以使用 artisan migrate 命令运行它

$ php artisan migrate --seed

运行此命令后,填充的国家表将可用