PHPackages                             hakanispirli/laravel-turkey-geo-database - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hakanispirli/laravel-turkey-geo-database

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

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.

v1.0.3(3mo ago)03MITPHPPHP ^8.2

Since Jan 31Pushed 3mo agoCompare

[ Source](https://github.com/hakanispirli/laravel-turkey-geo-database)[ Packagist](https://packagist.org/packages/hakanispirli/laravel-turkey-geo-database)[ Docs](https://webmarka.com)[ RSS](/packages/hakanispirli-laravel-turkey-geo-database/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (5)Used By (0)

Laravel Turkey Geo Database
===========================

[](#laravel-turkey-geo-database)

[![Latest Version](https://camo.githubusercontent.com/7c39ce76a670771551a7f15972e2be099e9138f877714c80c250fd434e8a95f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68616b616e69737069726c692f6c61726176656c2d7475726b65792d67656f2d64617461626173652e737667)](https://packagist.org/packages/hakanispirli/laravel-turkey-geo-database)[![Total Downloads](https://camo.githubusercontent.com/bb6ed3259c2da208c30a39400dc985c9ff135aa7d66a07c800fddc385a33365b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68616b616e69737069726c692f6c61726176656c2d7475726b65792d67656f2d64617461626173652e737667)](https://packagist.org/packages/hakanispirli/laravel-turkey-geo-database)[![License](https://camo.githubusercontent.com/59ef56ea0d191401a07965ea24463930f1ad4d7f960c967c58c03561e9929837/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f68616b616e69737069726c692f6c61726176656c2d7475726b65792d67656f2d64617461626173652e737667)](https://packagist.org/packages/hakanispirli/laravel-turkey-geo-database)

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
------------

[](#installation)

Install the package via Composer:

```
composer require hakanispirli/laravel-turkey-geo-database
```

Setup Options
-------------

[](#setup-options)

Choose the installation method that fits your needs:

### Option 1: Standard Installation (Most Common)

[](#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

[](#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
-----------

[](#basic-usage)

### Get All Cities

[](#get-all-cities)

```
use Webmarka\TurkeyGeo\Models\City;

$cities = City::all();
```

### Get Districts for a City

[](#get-districts-for-a-city)

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

### Get Neighborhoods for a District

[](#get-neighborhoods-for-a-district)

```
use Webmarka\TurkeyGeo\Models\District;

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

### Search by Postal Code

[](#search-by-postal-code)

```
use Webmarka\TurkeyGeo\Models\Neighborhood;

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

Common Use Cases
----------------

[](#common-use-cases)

### 1. City Dropdown for Forms

[](#1-city-dropdown-for-forms)

```
// Controller
public function create()
{
    $cities = City::orderBy('name')->get();
    return view('address.create', compact('cities'));
}
```

```

    Select City
    @foreach($cities as $city)
        {{ $city->name }}
    @endforeach

```

### 2. Dynamic District Loading (AJAX)

[](#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('Select District');
        districts.forEach(district => {
            $('#district_id').append(`${district.name}`);
        });
    });
});
```

### 3. Get Full Address Details

[](#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
------------------

[](#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)
------------------------

[](#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
-----------------

[](#advanced-features)

### Eager Loading Relationships

[](#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

[](#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

[](#caching-for-performance)

```
use Illuminate\Support\Facades\Cache;

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

Troubleshooting
---------------

[](#troubleshooting)

### Seeder Class Not Found

[](#seeder-class-not-found)

Run composer autoload dump:

```
composer dump-autoload
```

### Data Files Not Found Error

[](#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

[](#memory-issues-during-seeding)

Reduce batch size in config file:

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

Requirements
------------

[](#requirements)

- PHP ^8.2
- Laravel ^11.0 or ^12.0

What's Included
---------------

[](#whats-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
------------

[](#contributing)

Contributions are welcome! Please submit a Pull Request.

Security
--------

[](#security)

If you discover any security issues, please email .

Credits
-------

[](#credits)

- [Hakan İspirli](https://github.com/hakanispirli)
- [Webmarka](https://webmarka.com)
- PTT (Turkish Post) for official postal code data

License
-------

[](#license)

The MIT License (MIT). See [License File](LICENSE) for more information.

---

**Made with ❤️ by [Webmarka](https://webmarka.com)**

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance81

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

102d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/638f5b6295f2c4dea4c2ea2549fe86682cdd0481bc6c6712edeee9e263d60a5b?d=identicon)[webmarka360](/maintainers/webmarka360)

---

Top Contributors

[![hakanispirli](https://avatars.githubusercontent.com/u/119450201?v=4)](https://github.com/hakanispirli "hakanispirli (4 commits)")

---

Tags

laraveladdresslaravel 11laravel 12zip codegeocityseederturkeypostal-codegeographicTurkishdistrictneighborhoodpttil-ilce-mahalleposta-koduturkiye-adres

### Embed Badge

![Health badge](/badges/hakanispirli-laravel-turkey-geo-database/health.svg)

```
[![Health](https://phpackages.com/badges/hakanispirli-laravel-turkey-geo-database/health.svg)](https://phpackages.com/packages/hakanispirli-laravel-turkey-geo-database)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[pragmarx/zipcode

A worldwide address-by-zipcode searcher.

10265.4k](/packages/pragmarx-zipcode)[cuneytyuksel/turkey-cities

Turkey Cities and States - Türkiye İl ve İlçeler (PTT)

251.8k](/packages/cuneytyuksel-turkey-cities)[glhd/special

1929.4k](/packages/glhd-special)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
