承接 gerardojbaez/geodata 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

gerardojbaez/geodata

Composer 安装命令:

composer require gerardojbaez/geodata

包简介

Laravel 5.2 package that provides basic geographical data like Countries, Regions and Cities.

README 文档

README

GeoData is a Laravel package that provides basic geographical data like Countries, Regions and Cities.

Content

Installation

Composer

Pull this package through Composer (file composer.json)

{
    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.2.*",
        "gerardojbaez/geodata": "0.*"
    }
}

Run this command inside your terminal.

composer update

Service Provider

Add the package to your application service providers in config/app.php file.

<?php

'providers' => [

	[...]

	/**
	 * Third Party Service Providers...
	 */
	Gerardojbaez\GeoData\GeoDataServiceProvider::class,
]

Migrations and Seeders

Publish package migrations and seeders with:

php artisan vendor:publish

Then run migrations.

php artisan migrate

If you want all countries, run:

php artisan db:seed --class AllCountriesSeeder

If you want specific countries, run:

php artisan db:seed --class Gerardojbaez\\GeoData\\Seeders\\UnitedStatesSeeder
php artisan db:seed --class Gerardojbaez\\GeoData\\Seeders\\PuertoRicoSeeder
[...]

Check available countries below.

Available Countries

Countries
Afghanistan
Albania
Algeria
Andorra
Angola
Antigua and Barbuda
Argentina
Aruba
Australia
Austria
Bahamas
Barbados
Belgium
Belize
Bermuda
Bolivia
Brazil
Canada
Chile
China
Colombia
Costa Rica
Croatia
Cuba
Czech Republic
Denmark
Dominican Republic
Ecuador
El Salvador
Equatorial Guinea
Estonia
Finland
France
Germany
Greece
Greenland
Guatemala
Guyana
Haiti
Honduras
Hong Kong
India
Indonesia
Ireland
Israel
Italy
Ivory Coast
Jamaica
Japan
Latvia
Lebanon
Luxembourg
Malaysia
Mexico
Morocco
Netherlands
Nicaragua
Nigeria
Norway
Pakistan
Panama
Papua New Guinea
Paraguay
Peru
Philippines
Poland
Portugal
Puerto Rico
Romania
Russia
Saint Lucia
San Marino
Singapore
South Africa
Spain
Sri Lanka
Sweden
Switzerland
Thailand
Turkey
United Kingdom
United States
Uruguay
Venezuela

Traits and Contracts

You can use GeoData traits when you need to define a relation to countries, regions and/or cities.

See the following example:

<?php

namespace App\Models;

// [...]
use Gerardojbaez\GeoData\Contracts\HasCountryContract;
use Gerardojbaez\GeoData\Contracts\HasRegionContract;
use Gerardojbaez\GeoData\Contracts\HasCityContract;
use Gerardojbaez\GeoData\Traits\HasCountry;
use Gerardojbaez\GeoData\Traits\HasRegion;
use Gerardojbaez\GeoData\Traits\HasCity;

class User extends Model implements HasCountryContract, HasRegionContract, HasCityContract
{
	use HasCountry, HasRegion, HasCity;

	/**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'country_code',
        'region_id',
        'city_id',
        ...
    ];

Usage

Installing Countries

In addition to install countries via command line using seeders, you can also install countries through the CountryInstaller class. This will help you create a "web interface" that will give your customers or users the ability to install countries as needed. The installer will check if the country has been already installed and in that case will throw Gerardojbaez\Geodata\Exceptions\CountryAlreadyInstalledException.

The installation include:

  • The country
  • Country Regions
  • Country Cities

It's as simple as:

<?php

use Gerardojbaez\Geodata\CountryInstaller;

// Install United States.
$installer = new CountryInstaller('United States');
$installer->install();

// Install Puerto Rico.
$installer = new CountryInstaller('Puerto Rico');
$installer->install();

// Install Spain
$installer = new CountryInstaller('Spain');
$installer->install();

Models

This package comes with Gerardojbaez\GeoData\Models\Country, Gerardojbaez\GeoData\Models\Region and Gerardojbaez\GeoData\Models\City models.

Take a look at each model for more details.

Controllers

If you want to provide countries, regions and/or cities data to your frontend you may want to use Gerardojbaez\GeoData\Controllers\CountriesController, Gerardojbaez\GeoData\Controllers\RegionsController and Gerardojbaez\GeoData\Controllers\CitiesController controllers.

Controllers returns a json reponse containing (if any) the requested data.

Routes

This is an example. You can structure these routes as you want.

<?php

// Show countries list.
Route::get('api/geo/countries', [
	'uses' => '\Gerardojbaez\GeoData\Controllers\CountriesController@countries',
	'as' => 'geodata.countries'
]);

// Show regions list.
Route::get('api/geo/{country}/regions', [
	'uses' => '\Gerardojbaez\GeoData\Controllers\RegionsController@regions',
	'as' => 'geodata.regions'
]);

// Show cities list.
Route::get('api/geo/{country}/{region}/cities', [
	'uses' => '\Gerardojbaez\GeoData\Controllers\CitiesController@cities',
	'as' => 'geodata.cities'
]);

License

This package is free software distributed under the terms of the MIT license.

gerardojbaez/geodata 适用场景与选型建议

gerardojbaez/geodata 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.99k 次下载、GitHub Stars 达 31, 最近一次更新时间为 2016 年 07 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「countries」 「geographical data」 「cities」 「regions」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 gerardojbaez/geodata 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 gerardojbaez/geodata 我们能提供哪些服务?
定制开发 / 二次开发

基于 gerardojbaez/geodata 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 31
  • Watchers: 3
  • Forks: 13
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-07-22