adrianorosa/laravel-geolocation
Detect visitors' location in Laravel with this simple, configurable geolocation package. Resolve IP addresses to country, city, coordinates, timezone, currency, and more, with built-in caching and provider options. Great for localization, geo-targeted content, pricing, and compliance.
composer require adrianorosa/laravel-geolocation. Laravel's package auto-discovery should register the service provider; on older Laravel versions, check config/app.php for Adrianorosa\GeoLocation\GeoLocationServiceProvider and the accompanying facade alias (typically GeoLocation).php artisan vendor:publish --tag=geolocation-config (fall back to --provider="Adrianorosa\GeoLocation\GeoLocationServiceProvider"). Open config/geolocation.php to see the lookup endpoint, timeout, and any driver/cache options.vendor/adrianorosa/laravel-geolocation/README.md and skim src/ first — this is a small package, so the service class and facade accessor are the authoritative API. Confirm the exact method names (get(), locate(), find()) and the shape of the returned object.use Adrianorosa\GeoLocation\GeoLocation;
$geo = GeoLocation::get($request->ip());
$geo->country; // "Germany"
$geo->countryCode; // "DE"
$geo->city; // "Berlin"
App::setLocale() before the controller runs. Keep the mapping in config/geolocation.php or a dedicated config/locales.php.$geo = Cache::remember("geo:{$ip}", now()->addDay(), fn () => GeoLocation::get($ip));
GeolocationService that internally calls GeoLocation::get(). That way you can swap in a local MaxMind database later without touching controllers, and you centralize the timeout/fallback logic.127.0.0.1, 10.x, ::1) should return null; fall back to a default country/locale rather than throwing in a middleware.GeoLocation::shouldReceive('get')->andReturn((object) ['countryCode' => 'US']);
Or use Http::fake() if the package goes through Laravel's HTTP client.
countryCode, city, lat, lng) so downstream code isn't coupled to the package's field names.$request->ip() returns the load balancer's IP unless TrustProxies is configured correctly. Check X-Forwarded-For handling before blaming the package.config/geolocation.php. A blocked geolocation request hanging for 5+ seconds on every page load is the classic failure mode.php artisan config:cache, all env() calls must live in config files. If the package calls env() at runtime, it will silently break in production — check the service constructor.filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) before lookup."adrianorosa/laravel-geolocation": "^1.0") and review changelogs on upgrade. BSD-3-Clause is permissive, so forking is a viable escape hatch.$this->app->bind() in a custom provider. If it doesn't, the service-wrapper pattern from above is your extension point.null, log the raw response body from the upstream before the package parses it — most failures are quota exhaustion or an unexpected payload shape, not a bug in your code.How can I help you explore Laravel packages today?