sidm/laravel-subdivisions
Composer 安装命令:
composer require sidm/laravel-subdivisions
包简介
Laravel Subdivisions is a bundle for Laravel 4.2, providing what is roughly all ISO 3166_2 subdivisions (a.k.a., states, provinces, etc.) for all countries. Based on the awesome work Webpatser did in his laravel-countries package.
README 文档
README
Laravel Subdivisions is a bundle for Laravel 4.2, providing what is roughly all ISO 3166_2 subdivisions (a.k.a., states, provinces, etc.) for all countries. Based on the awesome work Webpatser did in his laravel-countries package.
Installation
Add sidm/laravel-subdivisions to composer.json.
"sidm/laravel-subdivisions": "dev-master"
Run composer update to pull down the latest version of the Subdivision List.
Edit app/config/app.php and add the provider and filter
'providers' => array(
'sidm\Subdivisions\SubdivisionsServiceProvider',
)
Now add the alias.
'aliases' => array(
'Subdivisions' => 'sidm\Subdivisions\SubdivisionsFacade',
)
Configuration
Start by publishing the configuration. The first variable is the table name, if the default name subdivisions is fine you should not modify it.
The next two variables are very important:
'country_table_name' => 'countries',
'iso_3166_2_column_name' => 'iso_3166_2',
If you only want subdivisions and do not have a countries table both of these values should be changed to null (i.e., ''). If you are using the Webpatser/laravel-countries package the defaults should work fine. If you are using another package, or have rolled your own, the country_table_name should be set to the table name that holds your list of countries, and iso_3166_2_column_name should be set to the name of the column that contains the iso_3166_2 values for each country.
When you have modified the configuration file (src/config/config.php) run the following command:
$ php artisan config:publish sidm/laravel-subdivisions
Model
Next generate the migration file:
$ php artisan subdivisions:migration
It will generate the <timestamp>_setup_subdivisions_table.php migration and the SubdivisionsSeeder.php seeder. To make sure the data is seeded insert the following code in the seeds/DatabaseSeeder.php
//Seed the subdivisions
$this->call('SubdivisionsSeeder');
$this->command->info('Seeded the subdivisions!');
You may now run it with the artisan migrate command:
$ php artisan migrate --seed
After running this command the filled subdivisions table will be available
Example
If you are using the Webpatser/laravel-countries package to use this in a form you can place the following in any controller:
$countries = Countries::lists('name', 'id');
$states = Subdivisions::where('country_id', '=', 840)->lists('region', 'id');
return View::make('yourview.create', compact('countries', 'states'));
Then in a form to use countries you may do the following:
{{ Form::label('country', 'Country') }}<br>
// 840 will default to the United States
{{ Form::select('country', $countries, '840') }}
Finally for states you may do the following:
{{ Form::label('state', 'State/Province/Region') }}<br>
// 4133 will default to Alabama
{{ Form::select('state', $states, '4133') }}
sidm/laravel-subdivisions 适用场景与选型建议
sidm/laravel-subdivisions 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 507 次下载、GitHub Stars 达 4, 最近一次更新时间为 2015 年 04 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「states」 「countries」 「iso_3166_2」 「subdivisions」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sidm/laravel-subdivisions 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sidm/laravel-subdivisions 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sidm/laravel-subdivisions 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
List of all countries with names and ISO 3166-1 codes in all languages and data formats for Laravel
PHP extension with Brazilian states and formats for CPF, CNPJ and ZIP
Laravel 5.2 package that provides basic geographical data like Countries, Regions and Cities.
A simple PHP class for United States Postal Service (USPS) addresses
Convert and operate with FIPS codes for states, counties, etc.
PHP Countries and Currencies
统计信息
- 总下载量: 507
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-04-02