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 issues](https://github.com/brainstudnl/geolocation/issues)[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 today

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

21

—

LowBetter than 18% of packages

Maintenance0

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

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

[nativephp/mobile

NativePHP for Mobile

1.1k75.1k91](/packages/nativephp-mobile)[spatie/laravel-health

Monitor the health of a Laravel application

87512.0M164](/packages/spatie-laravel-health)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

329530.5k29](/packages/codewithdennis-filament-select-tree)[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.

5021.9k](/packages/simplestats-io-laravel-client)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)

PHPackages © 2026

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