PHPackages                             diegocopat/laravel-geodata - 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. diegocopat/laravel-geodata

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

diegocopat/laravel-geodata
==========================

World countries + geographic data (regions, provinces, municipalities with postal codes) + Italian fiscal code (Codice Fiscale) for Laravel. Country-scoped: start with Italy, expand globally.

v1.0.2(1mo ago)05↑500%MITPHPPHP ^8.1

Since Mar 20Pushed 1mo agoCompare

[ Source](https://github.com/DiegoCopat/laravel-geodata)[ Packagist](https://packagist.org/packages/diegocopat/laravel-geodata)[ RSS](/packages/diegocopat-laravel-geodata/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (4)Used By (0)

Laravel Geodata
===============

[](#laravel-geodata)

World countries + geographic data (regions, provinces, municipalities) + Italian fiscal code (Codice Fiscale) for Laravel. Country-scoped: start with Italy, expand globally.

Features
--------

[](#features)

- **295 countries** with Belfiore codes (includes historical entities for fiscal code retroactive calculation)
- **20 Italian regions**, **107 provinces**, **~7,900 municipalities** with CAP, coordinates, Belfiore codes
- **Codice Fiscale**: generate, validate, and parse Italian fiscal codes
- Artisan commands for seeding, updating, and statistics
- Configurable table names to avoid conflicts
- Laravel 10/11/12/13 compatible

Installation
------------

[](#installation)

```
composer require diegocopat/laravel-geodata
```

The package auto-discovers the service provider. Publish the config (optional):

```
php artisan vendor:publish --tag=geodata-config
```

Run migrations and seed data:

```
php artisan migrate
php artisan geodata:seed
```

Configuration
-------------

[](#configuration)

```
// config/geodata.php

return [
    'tables' => [
        'countries' => 'countries',
        'regions' => 'regions',
        'provinces' => 'provinces',
        'cities' => 'cities',
    ],
    'include_historical_countries' => false,
];
```

Usage
-----

[](#usage)

### GeoData Facade

[](#geodata-facade)

```
use DiegoCopat\LaravelGeodata\Facades\GeoData;

// Countries
GeoData::countries();                          // active countries
GeoData::countries(includeHistorical: true);   // all 295 including historical
GeoData::searchCountries('Roman');             // search by name
GeoData::italy();                              // get Italy

// Regions & Provinces
GeoData::regions();
GeoData::provinces();
GeoData::provincesByRegion('04');              // by region code

// Cities
GeoData::cities();                             // all active cities
GeoData::citiesByProvince('TN');               // by province code
GeoData::searchCities('Trento');               // search by name
GeoData::searchCities('Rover', 'TN');          // search within province

// Lookups
GeoData::findByBelfiore('L378');               // city: Trento
GeoData::findByBelfiore('Z129');               // country: Romania
GeoData::findByCap('38122');                   // cities by postal code

// Utilities
GeoData::isItaly('IT');                        // true
```

### FiscalCode Facade

[](#fiscalcode-facade)

```
use DiegoCopat\LaravelGeodata\Facades\FiscalCode;

// Generate
$cf = FiscalCode::generate([
    'firstname' => 'Mario',
    'lastname' => 'Rossi',
    'gender' => 'M',
    'birth_date' => '1990-01-15',
    'birth_city' => 'Trento',
    'birth_province' => 'TN',
]);
// Returns: RSSMRA90A15L378X

// Generate with direct Belfiore code
$cf = FiscalCode::generate([
    'firstname' => 'Mario',
    'lastname' => 'Rossi',
    'gender' => 'M',
    'birth_date' => '1990-01-15',
    'belfiore_code' => 'L378',
]);

// Generate for foreign-born
$cf = FiscalCode::generate([
    'firstname' => 'Ion',
    'lastname' => 'Popescu',
    'gender' => 'M',
    'birth_date' => '1988-03-10',
    'birth_country' => 'Romania',
]);

// Validate
FiscalCode::validate('RSSMRA90A15L378X'); // true or false

// Parse
$data = FiscalCode::parse('RSSMRA90A15L378X');
// Returns:
// [
//     'surname_code' => 'RSS',
//     'firstname_code' => 'MRA',
//     'birth_year' => '1990',
//     'birth_month' => 1,
//     'birth_day' => 15,
//     'gender' => 'M',
//     'belfiore_code' => 'L378',
//     'birth_date' => '1990-01-15',
//     'birth_place' => 'Trento',
//     'is_foreign' => false,
//     'omocodia_level' => 0,
// ]
```

### Eloquent Models

[](#eloquent-models)

All models are available for direct queries:

```
use DiegoCopat\LaravelGeodata\Models\{Country, Region, Province, City};

// Scopes
Country::active()->get();
City::byProvince('TN')->get();
City::byBelfiore('L378')->first();
City::capitals()->get();

// Relationships
$city = City::find(1);
$city->province;
$city->province->region;
$city->province->region->country;

$province = Province::byCode('TN')->first();
$province->cities;
$province->region;
```

Artisan Commands
----------------

[](#artisan-commands)

### Seeding (country-scoped)

[](#seeding-country-scoped)

```
# Seed world countries + all available detail data (currently: Italy)
php artisan geodata:seed

# Seed world countries + only Italy detail (regions, provinces, cities)
php artisan geodata:seed --country=it

# Later: add Germany detail without touching Italy
php artisan geodata:seed --country=de

# Multiple countries at once
php artisan geodata:seed --country=it --country=de --country=fr

# Fresh reload — country-scoped (only clears Italy's regions/provinces/cities)
php artisan geodata:seed --country=it --fresh

# Fresh reload everything
php artisan geodata:seed --fresh

# Seed only countries (skip detail data)
php artisan geodata:seed --no-countries --country=it

# List available country data packages
php artisan geodata:seed --list
```

### Data management

[](#data-management)

```
# Update data files from remote source
php artisan geodata:update

# Preview changes without downloading
php artisan geodata:update --dry-run

# Show statistics
php artisan geodata:stats
```

### Adding a new country

[](#adding-a-new-country)

To add geographic data for a new country, create a directory under `database/data/countries/`:

```
database/data/countries/de/
├── regions.json       # German Bundesländer
├── provinces.json     # Kreise/Landkreise
├── cities.json        # Gemeinden
└── cap.json           # Postleitzahlen (optional)

```

Then run `php artisan geodata:seed --country=de`. See the `it/` directory for the expected JSON format.

Data Sources
------------

[](#data-sources)

- [DarioCorno/database\_comuni\_italiani](https://github.com/DarioCorno/database_comuni_italiani) — ISTAT-based Italian geographic data
- [Garda Informatica](https://www.gardainformatica.it/database-comuni-italiani) — Reference

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for details.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance89

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

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

3

Last Release

54d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c70577e74ba5670aa1db79f3b547a80572637e11a82326fc75357c8b8b3ed656?d=identicon)[DiegoCopat](/maintainers/DiegoCopat)

---

Top Contributors

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

---

Tags

laravelcountriescodice fiscaleregionsprovincesmunicipalitiesistatgeodatapostal-codescapfiscal codebelfiore

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/diegocopat-laravel-geodata/health.svg)

```
[![Health](https://phpackages.com/badges/diegocopat-laravel-geodata/health.svg)](https://phpackages.com/packages/diegocopat-laravel-geodata)
```

###  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)[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[zonneplan/laravel-module-loader

Module loader for Laravel

24118.4k](/packages/zonneplan-laravel-module-loader)[tehwave/laravel-achievements

Simple, elegant Achievements the Laravel way

7012.8k](/packages/tehwave-laravel-achievements)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)[juanparati/iso-codes

A PHP library that provides ISO codes, currencies, languages, timezones and additional geopolitical information

17146.4k](/packages/juanparati-iso-codes)

PHPackages © 2026

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