No description
Find a file
Troy Siedsma 6ffa817469 LICENSE: blank line between copyright holders so markdown actually breaks
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 16:50:21 +00:00
src Modernize for Laravel 11/12 2026-05-22 16:49:12 +00:00
.gitattributes Re-platform onto LithiumHosting/laravel-geoip Forgejo origin 2026-05-22 13:14:19 +00:00
.gitignore Re-platform onto LithiumHosting/laravel-geoip Forgejo origin 2026-05-22 13:14:19 +00:00
composer.json Modernize for Laravel 11/12 2026-05-22 16:49:12 +00:00
LICENSE.md LICENSE: blank line between copyright holders so markdown actually breaks 2026-05-22 16:50:21 +00:00
README.md Modernize for Laravel 11/12 2026-05-22 16:49:12 +00:00

Laravel GeoIP

Thin Laravel wrapper around the free geoPlugin IP geolocation service. Results are cached by IP-hash so repeated lookups for the same address don't re-hit the upstream API. Tested on PHP 8.2+ and Laravel 11/12.

Installation

composer require lithiumhosting/laravel-geoip

The service provider auto-registers. To use the facade with a shorter alias, register it in bootstrap/app.php or in config/app.php:

'aliases' => [
    'LaraGeo' => \LithiumHosting\LaraGeo\LaraGeoFacade::class,
],

Usage

use LithiumHosting\LaraGeo\LaraGeoFacade as LaraGeo;
use LithiumHosting\LaraGeo\LaraGeoException;

try {
    $info = LaraGeo::getInfo('8.8.8.8');
    // $info is a stdClass with geoplugin_* properties
    echo $info->geoplugin_city.', '.$info->geoplugin_countryName;
} catch (LaraGeoException $e) {
    // bad IP or upstream failure
}

Calling getInfo() without an argument falls through to the current request's client IP.

Trait usage

When you want to derive a "City, Region, Country" string from any class that owns an IP, add the trait:

use LithiumHosting\LaraGeo\Traits\GeoIp;

class Visitor
{
    use GeoIp;
}

$location = (new Visitor)->parseIp('8.8.8.8')->ipToCityStateCountry();
// "Mountain View, California, US"

The trait swallows upstream failures and falls back to a blank result so your render path doesn't blow up when the API is unreachable.

License

This package, laravel-geoip is licensed under The MIT License (MIT). Please see License File for more information.

Is it any good?

Yes.

When people first hear about a new product, they frequently ask if it is any good. A Hacker News user remarked:

Note to self: Starting immediately, all raganwald projects will have a "Is it any good?" section in the readme, and the answer shall be "yes.".