PHPackages                             brainstud/geolocation - 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. brainstud/geolocation

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

brainstud/geolocation
=====================

A laravel package to get the country and timezone (geolocation) of the request

v1.0.0(4y ago)15[3 PRs](https://github.com/brainstudnl/geolocation/pulls)MITPHPPHP ^8.1

Since May 2Pushed 2y ago1 watchersCompare

[ Source](https://github.com/brainstudnl/geolocation)[ Packagist](https://packagist.org/packages/brainstud/geolocation)[ Docs](https://github.com/brainstud/geolocation)[ RSS](/packages/brainstud-geolocation/feed)WikiDiscussions main Synced 1mo ago

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

Laravel Geolocation
===================

[](#laravel-geolocation)

[![Latest Version on Packagist](https://camo.githubusercontent.com/56018a15869774f92b0dd5847c6c12e42b5faaae197d5b1200a042683e2235ac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f627261696e737475642f67656f6c6f636174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/brainstud/geolocation)[![GitHub Tests Action Status](https://camo.githubusercontent.com/6153f243c134208b70b7262ac86f1b28d7a99e78ec7621da3936e0abaff6e2f1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f627261696e737475642f67656f6c6f636174696f6e2f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/brainstud/geolocation/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/5dce92fc617ffe74892d4de5b1eb1cb3d5117749a169121d42a4c6b3d9d20c2d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f627261696e737475642f67656f6c6f636174696f6e2f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/brainstud/geolocation/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/5c30bb1b43095ecff32e004199a4bbee904ba36daf0c6112adffd4951cc7f1cb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f627261696e737475642f67656f6c6f636174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/brainstud/geolocation)

Get the country &amp; timezone of the request with the cloudflare country header or fallback to a paid geo-locator API.

```
$location = Geolocation::getLocation($request);
// { countryCode: "NL", timeZone: "Europe/Amsterdam" }
```

The aim of this package prioritize the cloudflare header to keep costs down. Only if that fails an API-call will be done. By this philosophy only minimal info will be available. (country code and timezone)

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

[](#installation)

You can install the package via composer:

```
composer require brainstud/geolocation
```

You can publish the config file with:

```
php artisan vendor:publish --tag="geolocation-config"
```

This is the contents of the published config file:

```
return [
    'header' => 'CF-IPCountry', // The cloudflare header that contains the country code
    'geocoder' => GeoLocator::IpRegistry, // The geocoder to use if the header is empty
    'ip-registry' => [ // Credentials for the ip registry API
        'base_url' => env('IP_REGISTRY_URL', 'https://api.ipregistry.co'),
        'key' => env('IP_REGISTRY_KEY'),
    ],
    'ip-stack' => [ // Credentials for the ip stack API
        'base_url' => env('IP_STACK_URL', 'https://api.ipstack.com'),
        'key' => env('IP_STACK_KEY'),
    ],
    'cache_ttl' => DateInterval::createFromDateString('2 months'), // Cache TTL for the geocoder services.
];
```

Supported services
------------------

[](#supported-services)

- [Cloudflare IP geolocation](https://support.cloudflare.com/hc/en-us/articles/200168236-Configuring-Cloudflare-IP-Geolocation)
- [ipregistry](https://ipregistry.co/)
- [ipstack](https://ipstack.com)

Contributing
------------

[](#contributing)

You can add a geocoder by creating a class in the `src/GeoLocators` folder that implements `GeoLocatorContract`. Then add it to the `GeoLocator` enum and `GeoLocatorFactory`.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Credits
-------

[](#credits)

- [Niek Pijp](https://github.com/niekp)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Unknown

Total

1

Last Release

1475d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/59a4113e79a9d7d16cf8857d4f256eabf9cd2a546b692a9ffb02b2ab86799567?d=identicon)[Diondb](/maintainers/Diondb)

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

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (9 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (9 commits)")[![Diondb](https://avatars.githubusercontent.com/u/84917298?v=4)](https://github.com/Diondb "Diondb (1 commits)")

---

Tags

laravelgeolocationIPtimezonebrainstudipgeo

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/brainstud-geolocation/health.svg)

```
[![Health](https://phpackages.com/badges/brainstud-geolocation/health.svg)](https://phpackages.com/packages/brainstud-geolocation)
```

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M627](/packages/spatie-laravel-data)[maestroerror/laragent

Power of AI Agents in your Laravel project

630106.4k](/packages/maestroerror-laragent)[nativephp/mobile

NativePHP for Mobile

82724.0k43](/packages/nativephp-mobile)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[spatie/laravel-rdap

Perform RDAP queries in a Laravel app

72108.3k2](/packages/spatie-laravel-rdap)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)

PHPackages © 2026

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