Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Location Laravel Package

stevebauman/location

Retrieve a user’s geolocation from their IP in Laravel. Provides a simple Location facade to get city, region, country, coordinates, timezone and more, with multiple driver support (e.g., IP2Location, IP-API, MaxMind) plus caching and testing helpers.

View on GitHub
Deep Wiki
Context7

Retrieve a user's location by their IP Address

Frequently asked questions about Location
How do I install and set up stevebauman/location in Laravel?
Run `composer require stevebauman/location`, then publish the config with `php artisan vendor:publish --tag=location-config`. Configure your preferred driver (e.g., MaxMind or IPAPI) in `config/location.php`, and you’re ready to use `Location::get()` in your code.
Which geolocation providers does this package support?
The package supports MaxMind (local or web service), IPAPI, IP2Location, and custom drivers. You can switch providers by updating the `driver` key in the config file without changing your application logic.
Can I use this package with Laravel middleware for geo-blocking?
Yes, the package includes `GeoRestrictMiddleware` for route-level geo-blocking. Use it like this: `Route::middleware(['geo.restrict' => ['EU']])->group(...)` to restrict access to specific regions.
How do I cache geolocation results to reduce API calls?
Enable caching by setting `cache_enabled` to `true` in the config and configuring `cache_ttl` (time-to-live in minutes). The package uses Laravel’s cache system, so you can integrate with Redis, Memcached, or file caching.
Does stevebauman/location support IPv6 addresses?
Support varies by provider. MaxMind handles IPv6 well, but IPAPI may not. Test with your target IPs early, and configure a fallback driver in the config if needed.
How can I mock geolocation data for testing?
Use the `Location::fake()` method to simulate geolocation responses in tests. For example: `Location::fake(['countryCode' => 'US', 'ip' => '192.0.2.1'])` ensures consistent test results without hitting external APIs.
What Laravel versions does this package support?
The package supports Laravel 8 through 13. For long-term projects, pin your Composer dependency to a specific minor version (e.g., `^7.6`) to avoid unexpected breaking changes.
How do I handle GDPR/CCPA compliance with stored IP addresses?
Anonymize IPs post-lookup by setting `Location::get()->ip = null` or use `Location::forget()` to purge cached data. Avoid storing raw IPs unless absolutely necessary, and ensure your config respects data protection laws.
What’s the best free geolocation provider for high accuracy?
For free tiers, IPAPI offers decent accuracy but may have rate limits. For higher precision, consider MaxMind’s free GeoLite2 database (local setup) or their commercial web service. Test providers with your expected traffic volume.
Can I extend the package to add custom geolocation logic?
Yes, the package supports macros and custom drivers. For example, add a macro like `Location::macro('isEu', fn() => Location::get()->countryCode->startsWith('DE|FR|...'))` for region-specific checks.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope