承接 hakanispirli/laravel-turkey-geo-database 相关项目开发

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

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

hakanispirli/laravel-turkey-geo-database

Composer 安装命令:

composer require hakanispirli/laravel-turkey-geo-database

包简介

Laravel package for Turkish geographic data (cities, districts, neighborhoods) based on PTT database. Includes 81 cities, 900+ districts, and 50,000+ neighborhoods with postal codes.

README 文档

README

Latest Version Total Downloads License

Complete Turkish geographic data package for Laravel applications. Get all Turkish cities, districts, and neighborhoods with postal codes in your database with just a few commands.

Installation

Install the package via Composer:

composer require hakanispirli/laravel-turkey-geo-database

Setup Options

Choose the installation method that fits your needs:

Option 1: Standard Installation (Most Common)

Use this if you want the default database structure without modifications.

# 1. Publish migrations (creates timestamped migration files)
php artisan vendor:publish --tag=turkey-geo-migrations

# 2. Publish data files
php artisan vendor:publish --tag=turkey-geo-data

# 3. Run migrations
php artisan migrate

# 4. Seed the database
php artisan db:seed --class="Webmarka\TurkeyGeo\Database\Seeders\TurkeyGeoSeeder"

That's it! Your database now contains all Turkish geographic data.

Option 2: Custom Installation

Use this if you need to modify the database structure (add columns, change types, etc.).

# 1. Publish migrations
php artisan vendor:publish --tag=turkey-geo-migrations

# 2. Customize the migration files in database/migrations/
# Add your custom columns, indexes, or modifications

# 3. Publish data files
php artisan vendor:publish --tag=turkey-geo-data

# 4. Run migrations
php artisan migrate

# 5. Seed the database
php artisan db:seed --class="Webmarka\TurkeyGeo\Database\Seeders\TurkeyGeoSeeder"

💡 Pro Tip: Migration files are published with current timestamps, so they'll run after your existing migrations without conflicts.

⏱️ Seeding Time: Approximately 30-60 seconds to insert all data with progress tracking.

Basic Usage

Get All Cities

use Webmarka\TurkeyGeo\Models\City;

$cities = City::all();

Get Districts for a City

$ankara = City::where('name', 'ANKARA')->first();
$districts = $ankara->districts;

Get Neighborhoods for a District

use Webmarka\TurkeyGeo\Models\District;

$district = District::find(1);
$neighborhoods = $district->neighborhoods;

Search by Postal Code

use Webmarka\TurkeyGeo\Models\Neighborhood;

$neighborhoods = Neighborhood::where('postal_code', '06100')->get();

Common Use Cases

1. City Dropdown for Forms

// Controller
public function create()
{
    $cities = City::orderBy('name')->get();
    return view('address.create', compact('cities'));
}
<!-- Blade View -->
<select name="city_id">
    <option value="">Select City</option>
    @foreach($cities as $city)
        <option value="{{ $city->id }}">{{ $city->name }}</option>
    @endforeach
</select>

2. Dynamic District Loading (AJAX)

// Route
Route::get('/api/districts/{cityId}', function ($cityId) {
    return District::where('city_id', $cityId)
        ->orderBy('name')
        ->get(['id', 'name']);
});
// JavaScript
$('#city_id').change(function() {
    let cityId = $(this).val();
    $.get(`/api/districts/${cityId}`, function(districts) {
        $('#district_id').html('<option value="">Select District</option>');
        districts.forEach(district => {
            $('#district_id').append(`<option value="${district.id}">${district.name}</option>`);
        });
    });
});

3. Get Full Address Details

$neighborhood = Neighborhood::with('district.city')->find($id);

echo $neighborhood->name; // Neighborhood name
echo $neighborhood->district->name; // District name
echo $neighborhood->district->city->name; // City name
echo $neighborhood->postal_code; // Postal code

Database Structure

cities

  • id - City ID (1-81)
  • name - City name

districts

  • id - District ID
  • city_id - Belongs to city
  • name - District name

neighborhoods

  • id - Neighborhood ID
  • district_id - Belongs to district
  • name - Neighborhood name
  • area - Area/region information
  • postal_code - PTT postal code

Configuration (Optional)

You can customize table names, seeding batch size, and other options:

php artisan vendor:publish --tag=turkey-geo-config

Edit config/turkey-geo.php to customize:

  • Table names
  • Seeding batch size
  • Progress display options

Advanced Features

Eager Loading Relationships

// Load city with all its districts
$city = City::with('districts')->find(7);

// Load district with neighborhoods
$district = District::with('neighborhoods')->find(1);

Validation Example

use Illuminate\Validation\Rule;

public function rules()
{
    return [
        'city_id' => 'required|exists:cities,id',
        'district_id' => [
            'required',
            Rule::exists('districts', 'id')->where('city_id', $this->city_id),
        ],
        'neighborhood_id' => [
            'required',
            Rule::exists('neighborhoods', 'id')->where('district_id', $this->district_id),
        ],
    ];
}

Caching for Performance

use Illuminate\Support\Facades\Cache;

$cities = Cache::remember('turkish-cities', 3600, function () {
    return City::orderBy('name')->get();
});

Troubleshooting

Seeder Class Not Found

Run composer autoload dump:

composer dump-autoload

Data Files Not Found Error

Make sure you published the data files:

php artisan vendor:publish --tag=turkey-geo-data

Verify files exist in database/data/turkey-geo/ directory.

Memory Issues During Seeding

Reduce batch size in config file:

// config/turkey-geo.php
'seeding' => [
    'batch_size' => 500, // Default is 1000
],

Requirements

  • PHP ^8.2
  • Laravel ^11.0 or ^12.0

What's Included

  • 81 Turkish Cities (İller)
  • 900+ Districts (İlçeler)
  • 50,000+ Neighborhoods (Mahalleler)
  • PTT Postal Codes for all neighborhoods
  • Optimized Performance with indexed database columns
  • Eloquent Models with pre-configured relationships
  • Progress Tracking during data seeding

Contributing

Contributions are welcome! Please submit a Pull Request.

Security

If you discover any security issues, please email destek@webmarka.com.

Credits

License

The MIT License (MIT). See License File for more information.

Made with ❤️ by Webmarka

hakanispirli/laravel-turkey-geo-database 适用场景与选型建议

hakanispirli/laravel-turkey-geo-database 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 92 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 31 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 hakanispirli/laravel-turkey-geo-database 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 92
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 54
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-31