PHPackages                             rahasistiyak/laravel-geo-data - 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. rahasistiyak/laravel-geo-data

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

rahasistiyak/laravel-geo-data
=============================

A Laravel package providing optimized access to region, country, phone code, city, and currency data

2.3.2(10mo ago)217MITPHPPHP ^7.3|^8.0|^8.1|^8.2|^8.3|^8.4

Since Jun 25Pushed 10mo agoCompare

[ Source](https://github.com/rahasistiyakofficial/laravel-geo-data)[ Packagist](https://packagist.org/packages/rahasistiyak/laravel-geo-data)[ Docs](https://github.com/rahasistiyakofficial/laravel-geo-data)[ RSS](/packages/rahasistiyak-laravel-geo-data/feed)WikiDiscussions main Synced 1mo ago

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

Laravel Geo Data
================

[](#laravel-geo-data)

An optimized Laravel package for accessing region, country, phone code, city, and currency data.

Compatibility
-------------

[](#compatibility)

- **PHP**: 7.3+, 8.0+
- **Laravel**: 6.x, 7.x, 8.x, 9.x, 10.x, 11.x, 12.x

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

[](#installation)

To install the package, run the following command:

```
composer require rahasistiyak/laravel-geo-data
```

The package will be auto-discovered by Laravel.

### Publish the Configuration File (if needed)

[](#publish-the-configuration-file-if-needed)

If you'd like to publish the configuration file for customization, use:

```
php artisan vendor:publish --tag=geo-data-config
```

This will publish the configuration file to `config/geo-data.php`.

Usage
-----

[](#usage)

### Regions

[](#regions)

You can interact with the **regions** model as follows:

```
use RahasIstiyak\GeoData\Models\Region;

$regions = Region::all(); // All regions
$dropdown = Region::dropdown(); // ['id', 'name']
$region = Region::byId(1); // By ID
$page = Region::paginate(10, 1); // Paginated results
```

### Countries

[](#countries)

You can interact with the **countries** model as follows:

```
use RahasIstiyak\GeoData\Models\Country;

$countries = Country::all(); // All countries
$dropdown = Country::dropdown(['id', 'name', 'code']); // Custom fields default if no parameter ['id','name']- if you need more data then send it in parameter
$country = Country::byCode('AF'); // By ISO2/code or ISO3
$country = Country::byId(1); // By ID
$regionCountries = Country::byRegion(3); // By region ID
$page = Country::paginate(10, 1); // Paginated results
```

### Phone Codes

[](#phone-codes)

You can interact with the **phone codes** model as follows:

```
use RahasIstiyak\GeoData\Models\PhoneCode;

$phoneCodes = PhoneCode::all(); // All phone codes
$dropdown = PhoneCode::dropdown(); // ['country_id', 'phonecode']
$phoneCode = PhoneCode::byCountryId(1); // By country ID
$page = PhoneCode::paginate(10, 1); // Paginated results
```

### Cities

[](#cities)

You can interact with the **cities** model as follows:

```
use RahasIstiyak\GeoData\Models\City;

$cities = City::getCities('US'); // All cities in the United States
$dropdown = City::getCityDropdown('US'); // Dropdown ['id', 'name'] for the United States
// If you need more data, send parameters like ['id', 'name', 'latitude']
$dropdownWithAdditionalFields = City::getCityDropdown('US', ['id', 'name', 'latitude']); // Additional fields

$city = City::getCityById('US', 1); // Get city with ID 1 in the United States
```

### Currencies

[](#currencies)

You can interact with the **currencies** model as follows:

```
use RahasIstiyak\GeoData\Models\Currency;

$currencies = Currency::all(); // All currencies
$dropdown = Currency::dropdown(); // ['country_id', 'currency', 'currency_name']
$currency = Currency::byCountryId(1); // By country ID
$currency = Currency::byCode('AFN'); // By currency code
$page = Currency::paginate(10, 1); // Paginated results
```

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

[](#configuration)

You can edit the configuration in `config/geo-data.php`. The configuration file includes options for enabling/disabling specific data types and setting cache duration.

```
return [
    'enabled_data' => [
        'regions' => true,
        'countries' => true,
        'phone_codes' => true,
        'cities' => true,
        'currencies' => true,
    ],
    'cache_ttl' => 1440, // Cache duration in minutes
];
```

Test Usage
----------

[](#test-usage)

To test the functionality, you can add the following route in your `routes/web.php` file:

```
use RahasIstiyak\GeoData\Models\Country;
use RahasIstiyak\GeoData\Models\City;

Route::get('/test-geo', function () {
    return response()->json([
        'countries' => Country::dropdown(),// you can send parameter for custom fields eg: ['id', 'name', 'code']
        'country_af' => Country::byCode('AF'),
        'country_1' => Country::byId(1),
        'cities_us' => City::getCities('US'), // Cities for the United States
        'city_1_us' => City::getCityById('US', 1), // City with ID 1 for US

    ]);
});
```

This will give you a sample response for countries and cities data.

Why This is Optimized
---------------------

[](#why-this-is-optimized)

- **Memory Efficiency**: Caching with `Cache::remember` reduces file I/O and memory usage for repeated calls.
- **Code Reusability**: The `BaseGeoModel` class eliminates duplicate logic across models.
- **Large Dataset Handling**: The `paginate` method allows partial loading of large datasets, like cities, to avoid memory overflow.
- **Error Handling**: The package validates data files and logs warnings for any missing or corrupted files.
- **Flexibility**: Dropdown fields and sorting are customizable to suit different use cases.
- **Performance**: Configuration checks are done once during data loading, and cache TTL is configurable for optimized performance.

---

### **License**

[](#license)

This package is open-source and available under the **MIT License**.

---

### **Contact**

[](#contact)

For any questions or support, you can reach us at: **Email**:

```

### Changes Made:

## [1.0.0] - 2025-06-25
- Initial release with optimized region, country, phone code, city, and currency data access.

## [1.1.0] - 2025-06-26
- Optimized region, country, phone code, city, and currency data access.

## [2.0.0] - 2025-06-26
### Changes Made:
- Updated **Cities** section to reflect the new methods: `getCities()`, `getCityById()`, and `getCityDropdown()`.
- Added example code to demonstrate how these methods can be used.

## [2.1.0] - 2025-06-27
### Changes Made:
- **Added Chunked Caching** for large city datasets to handle **database cache driver** more effectively.
    - Divided the caching process into smaller chunks to avoid exceeding MySQL’s packet size.
    - Introduced `cacheInChunks()` to store the cities data in smaller parts and retrieve them efficiently.
    - This change ensures that caching large city data in the database cache driver doesn't lead to the "MySQL server has gone away" error.
- **Performance Improvement**: Optimized city data retrieval by caching in chunks and merging data from multiple chunks.
- **Database Cache Driver Compatibility**: The chunked caching strategy now ensures compatibility with the database cache driver (`CACHE_DRIVER=database`), preventing large cache payload issues.

## [2.2.0] - 2025-06-27
### Changes Made:
- **Optimized Chunked Caching** for large city datasets to handle **database cache driver** more effectively.
- **Duplicate City Removal**: Remove Duplicate Cities from Dataset.

## [2.3.0] - 2025-06-28
### Changes Made:
- **All Data Return Types Array to Collection** Use $data->name insted of $data['name']

```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance54

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81.8% 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

5

Last Release

320d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/64626fc08fcee19f6c990dd464377015cb4cb02413c0f96d50b639c166aa72e3?d=identicon)[rahasistiyakofficial](/maintainers/rahasistiyakofficial)

---

Top Contributors

[![IstiyakCPL](https://avatars.githubusercontent.com/u/182621267?v=4)](https://github.com/IstiyakCPL "IstiyakCPL (18 commits)")[![rahasistiyakofficial](https://avatars.githubusercontent.com/u/121127883?v=4)](https://github.com/rahasistiyakofficial "rahasistiyakofficial (4 commits)")

---

Tags

laravelcurrencylocationgeocountrycityISO codesregionPhone codegeodataLaravel-Countriesgeo databaselaravel world data

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rahasistiyak-laravel-geo-data/health.svg)

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

###  Alternatives

[stevebauman/location

Retrieve a user's location by their IP Address

1.3k7.6M65](/packages/stevebauman-location)[dipeshsukhia/laravel-country-state-city-data

Country State City Data Provider

8230.8k](/packages/dipeshsukhia-laravel-country-state-city-data)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)[dive-be/laravel-geo

Translate IP addresses into geo locations

3710.5k](/packages/dive-be-laravel-geo)[nevadskiy/laravel-geonames

Populate your database using the GeoNames service.

2715.1k](/packages/nevadskiy-laravel-geonames)[hibit-dev/geodetect

Automatically detect user's geo data based on their IP address

2319.5k](/packages/hibit-dev-geodetect)

PHPackages © 2026

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