ermradulsharma / omnilocate
OmniLocate: Advanced user location detection for Laravel with persistence, caching, and distance utilities.
Fund package maintenance!
ermradulsharma
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/ermradulsharma/omnilocate
Requires
- php: >=7.0
- ext-curl: *
- ext-json: *
- geoip2/geoip2: ^2.0|^3.0
- illuminate/support: ^7.0|^8.0|^9.0|^10.0|^11.0|^12.0
Requires (Dev)
- mockery/mockery: ^1.0
- orchestra/testbench: ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0
README
OmniLocate
OmniLocate is a premium, high-performance user location detection package for Laravel. It provides a robust, developer-friendly API for identifying visitor details via IP address, featuring advanced caching, multi-driver support with intelligent fallbacks, and seamless integration with CDNs like Cloudflare and Akamai.
๐ Key Features
- ๐ Intelligent Detection: Works out-of-the-box with various IP services and CDN headers.
- ๐ก๏ธ Smart Fallbacks: Chain multiple drivers to ensure location data is always available.
- โก Performance First: Integrated Laravel caching to minimize external API calls.
- ๐ Geo-Utilities: Built-in distance calculation between any two detected points.
- ๐ค Bot Filtering: Automatically skips detection for major search engine bots.
- ๐งฉ Fluent API: Elegant, human-readable syntax for all operations.
- ๐จ Blade Integration: Simple directives to display location data directly in your templates.
๐ ๏ธ Installation
Install OmniLocate via Composer:
composer require ermradulsharma/omnilocate
The package will automatically register its service provider and facade.
Configuration
Publish the configuration file to customize your drivers and settings:
php artisan vendor:publish --provider="Ermradulsharma\OmniLocate\LocationServiceProvider"
This creates config/location.php (or config/config.php depending on your setup).
๐ Basic Usage
Detect Current Visitor
Detect the location of the current user based on their IP address:
use Ermradulsharma\OmniLocate\Facades\Location; if ($position = Location::get()) { echo $position->countryName; // "India" echo $position->cityName; // "Mumbai" echo $position->flag(); // "๐ฎ๐ณ" }
Detect Specific IP
$position = Location::get('8.8.8.8');
๐ Advanced Driver Chain & Fallbacks
OmniLocate excels at reliability. You can define a default driver and any number of fallbacks in your configuration, or add them dynamically:
Dynamic Fallbacks
use Ermradulsharma\OmniLocate\Facades\Location; use Ermradulsharma\OmniLocate\Drivers\IpApi; // Add a fallback driver dynamically at runtime Location::fallback(new IpApi());
๐งฉ Extra Features
Blade Directives
Quickly display location info in your views:
Current Country: @location('countryName') Your Flag: @location('flag')
Distance Utilities
Calculate the distance in Kilometers between two locations:
$distance = $position->distanceTo($otherPosition);
Validation Rules
Ensure users are from a specific location using Laravel's validation:
$request->validate([ 'signup_ip' => 'required|location:India', ]);
๐ฆ Supported Drivers
OmniLocate supports a variety of drivers out of the box:
- HttpHeader: (Default) Detects location via CDN headers like
CF-IPCountry. - IpApi: Free and Pro IP-API service.
- IpData: Powerful IP Intelligence API.
- IpInfo: Detailed IP address data.
- GeoPlugin: Simple and effective geolocation service.
- MaxMind: Local database and web service support.
๐งช Testing
Run the test suite using PHPUnit:
vendor/bin/phpunit
๐ค Support & Funding
If you find this package useful, please consider supporting the developer:
- Sponsor: Support Mradul Sharma on GitHub
- Repo: GitHub Repository
โ๏ธ License
Distributed under the MIT License. See LICENSE for more information.
