PHPackages                             danielme85/laravel-geoip2 - 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. danielme85/laravel-geoip2

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

danielme85/laravel-geoip2
=========================

Service provider and DB downloader for Maxminds PHP API GeoIP2.

v2.0.0(1mo ago)15182.0k↓41.1%2MITPHPPHP ^8.3CI passing

Since Jan 9Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/danielme85/laravel-geoip2)[ Packagist](https://packagist.org/packages/danielme85/laravel-geoip2)[ RSS](/packages/danielme85-laravel-geoip2/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (4)Dependencies (10)Versions (7)Used By (0)

laravel-geoip2
==============

[](#laravel-geoip2)

Laravel service provider and database downloader for [MaxMind's GeoIP2 PHP API](https://github.com/maxmind/GeoIP2-php).

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![Tests](https://github.com/danielme85/laravel-geoip2/actions/workflows/tests.yml/badge.svg)](https://github.com/danielme85/laravel-geoip2/actions/workflows/tests.yml)

**Requirements:** PHP 8.3+, Laravel 13.x

> MaxMind requires a free account to download GeoLite2 databases. Sign up at [maxmind.com](https://www.maxmind.com/en/geolite2/signup) to get a license key.

Install
-------

[](#install)

```
composer require danielme85/laravel-geoip2
```

Add your license key to `.env`:

```
GEOIP2_LICENSE=YOUR_LICENSE_KEY

```

Publish the config file:

```
php artisan vendor:publish --provider="danielme85\Geoip2\Geoip2ServiceProvider"
```

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

[](#configuration)

`config/geoip2.php`:

```
return [
    'downloadUrl' => 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&suffix=tar.gz',
    'folder'      => 'app/geoip2',       // path inside storage/
    'filename'    => 'GeoLite2-City.mmdb',
    'localhost'   => '8.8.8.8',          // fallback IP when running locally
    'license'     => env('GEOIP2_LICENSE', ''),
];
```

Usage
-----

[](#usage)

Download the database (~30 MB download, ~50 MB extracted):

```
php artisan geoip:download
```

Then use the `Reader` facade — the returned object is a [`GeoIp2\Database\Reader`](https://github.com/maxmind/GeoIP2-php), so all MaxMind methods apply directly:

```
use danielme85\Geoip2\Facade\Reader;

$reader = Reader::connect();
$city   = $reader->city('8.8.8.8');

echo $city->city->name;               // "Mountain View"
echo $city->country->isoCode;         // "US"
echo $city->location->latitude;       // 37.386
echo $city->location->longitude;      // -122.0838
```

### Handling CloudFlare (or other proxies)

[](#handling-cloudflare-or-other-proxies)

```
$ip     = $_SERVER['HTTP_CF_CONNECTING_IP'] ?? $request->ip();

try {
    $geodata = Reader::connect()->city($ip)->jsonSerialize();
} catch (\GeoIp2\Exception\AddressNotFoundException $e) {
    // IP not found in database
}
```

Re-downloading the database
---------------------------

[](#re-downloading-the-database)

The downloaded `.tar.gz` archive is kept in `storage/{folder}/tmp/`. Running `geoip:download` again will prompt before fetching a new copy, so you can re-extract from the cached archive or force a fresh download.

---

This product includes GeoLite2 data created by MaxMind, available from [maxmind.com](http://www.maxmind.com).

###  Health Score

61

—

FairBetter than 98% of packages

Maintenance94

Actively maintained with recent releases

Popularity41

Moderate usage in the ecosystem

Community13

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 92.1% 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 ~778 days

Total

4

Last Release

32d ago

Major Versions

v1.2.0 → v2.0.02026-06-02

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1576219?v=4)[Daniel Mellum](/maintainers/danielme85)[@danielme85](https://github.com/danielme85)

---

Top Contributors

[![danielme85](https://avatars.githubusercontent.com/u/1576219?v=4)](https://github.com/danielme85 "danielme85 (35 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![poinchy](https://avatars.githubusercontent.com/u/1609826?v=4)](https://github.com/poinchy "poinchy (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/danielme85-laravel-geoip2/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5022.0k](/packages/simplestats-io-laravel-client)[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1235.9k20](/packages/fleetbase-core-api)[aedart/athenaeum

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

245.2k](/packages/aedart-athenaeum)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)

PHPackages © 2026

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