Laravel Geo Genius

Laravel Geo Genius stats

Downloads
10
Stars
3
Open Issues
0
Forks
0

View on GitHub →

Laravel GeoGenius — A powerful, intelligent toolkit for geo-location, timezone, and locale-based features in Laravel applications.

📦 Laravel GeoGenius — Timezone, Geolocation, Multilingual Toolkit & Country Picker for Laravel

Laravel GeoGenius is a lightweight, flexible package for Laravel applications that handles:

  • 🌐 Geolocation — Detect user location via IP
  • 🕒 Timezone Management — Detect and convert user timezones automatically
  • 🏷️ Multilingual & Translation Support — Auto-detect locale, translate messages, and even convert numbers
  • 📱 Country Picker & Phone Validation — Auto-detect default country, show a dropdown of all countries, format and validate numbers automatically

It automatically retrieves detailed IP-based location data, detects the user’s timezone, sets the correct locale, and even initialises a fully-functional phone input field with country picker and validation — all seamlessly integrated into your app.

✅ Fully compatible with Livewire, works via cookies or headers, and enables a truly global-ready Laravel application.


🚀 Live Demo

👉 Try the Live Demo


✨ Key Features

  • 🌐 Automatic Timezone Detection — via cookies, headers, or fallback strategies
  • 🧠 Timezone Conversion Helpers — convert timestamps automatically
  • 📱 Country Picker & Phone Validation — detect visitor’s country, show dropdown, format & validate numbers
  • Lightweight & Dependency-Free — no jQuery or frontend frameworks required
  • 🔄 Livewire Compatible — works seamlessly with Livewire apps
  • 🔧 Configurable Detection Strategy — customise detection method per app requirements
  • 📦 Migration & Artisan Support — add timezone column effortlessly
  • 🔒 Caching & Offline Support — reduces API calls and handles offline gracefully
  • 🌍 Multilingual Ready — built-in translation and auto-translation support

Under the hood, it leverages reliable IP geolocation APIs like ipwho.is and ip-api.com with caching for optimal performance.


📦 Installation

composer require devrabiul/laravel-geo-genius

Publish the configuration and migration stub:

php artisan vendor:publish --provider="Devrabiul\\LaravelGeoGenius\\LaravelGeoGeniusServiceProvider"

⚡ Quick Start

Use Laravel GeoGenius in two ways:

  1. Global HelperlaravelGeoGenius() (recommended)
  2. 🧰 Service Class — manually instantiate GeoLocationService

Global Helper

laravelGeoGenius()->geo()->locateVisitor();
laravelGeoGenius()->geo()->getCountry();
laravelGeoGenius()->geo()->getTimezone();
laravelGeoGenius()->geo()->getLatitude();

Service Class

use Devrabiul\LaravelGeoGenius\Services\GeoLocationService;
 
$geo = new GeoLocationService();
 
$ip = $geo->getClientIp();
$locationData = $geo->locateVisitor();

🌐 Multilingual & Translation

Built-in auto translation and number conversion:

use function Devrabiul\LaravelGeoGenius\geniusTrans;
use function Devrabiul\LaravelGeoGenius\geniusTranslateNumber;
 
echo geniusTrans('welcome_message');
echo geniusTranslateNumber(12345); // Bengali digits if locale is 'bn'

Configure in config/laravel-geo-genius.php:

'translate' => [
'auto_translate' => true,
],

🌐 Change Current User Language

You can programmatically change the current user's language using the changeUserLanguage method:

use Illuminate\Support\Facades\Route;
 
Route::get('/change-lang', function () {
// Change current user language to Bengali
laravelGeoGenius()->language()->changeUserLanguage('bn');
 
// Continue your logic
return redirect()->back();
});

Supported locale codes depend on your configuration (config/laravel-geo-genius.php) and the languages you have added via geo:add-language.

🛠 Timezone Artisan Commands

Laravel GeoGenius ships with helpful artisan commands:

Command Description
php artisan geo:add-language {locale} Add a new language (e.g. en, bn) to your app.

Examples

# Add Bengali language
php artisan geo:add-language bn

🕒 Timezone Detection & Conversion

use Devrabiul\LaravelGeoGenius\Services\TimezoneService;
 
$tz = new TimezoneService();
 
// Detect user's timezone
$timezone = $tz->getUserTimezone();
 
// Convert UTC datetime to user timezone
echo $tz->convertToUserTimezone('2025-09-13 15:00:00');

🛠 Timezone Artisan Commands

Laravel GeoGenius ships with helpful artisan commands:

Command Description
php artisan geo:add-timezone-column {table} Add a nullable timezone column to the specified table if it does not exist.

Examples

# Add a timezone column to the 'users' table
php artisan geo:add-timezone-column users

📱 Country Picker & Phone Input

Laravel GeoGenius makes it trivial to initialise a country-aware phone input field:

  • Auto-detects visitor’s default country
  • Displays country dropdown (or restrict to one country)
  • Formats phone numbers as the user types
  • Provides built-in validation for numbers

Quick Blade Example

<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
 
// must be use type="tel" in your phone input
<input id="phone" type="tel" name="phone">
 
// Before Body close tag
{!! laravelGeoGenius()->initIntlPhoneInput() !!}
</body>
</html>

GeoGenius injects the detected country code into a hidden span:

<span class="system-default-country-code" data-value="us"></span>

Then you can use intl-tel-input’s API to validate on submit:

const input = document.querySelector("#phone");
const iti = window.intlTelInput(input, {
initialCountry: document.querySelector('.system-default-country-code').dataset.value,
utilsScript: "https://cdn.jsdelivr.net/npm/intl-tel-input@19.2.15/build/js/utils.js",
});
 
form.addEventListener('submit', e => {
if (!iti.isValidNumber()) {
e.preventDefault();
alert('Please enter a valid phone number');
}
});

All scripts/styles are included automatically by initIntlPhoneInput() — you only need to add the <input> and optionally the validation snippet.


🧠 Additional Notes

  • 🌐 APIs Used: ipify.org, ipwho.is
  • 🔐 Caching: Geo data cached 7 days per IP (ttl_minutes = cache lifetime in minutes)
  • ⚙️ Fallback: Returns default structure if offline
  • 🧪 Localhost Handling: Fetches external IP for 127.0.0.1 or ::1

🤝 Contributing

We welcome contributions! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Report bugs through GitHub Issues.


🌱 Treeware

This package is Treeware. If you use it in production, please buy the world a tree to thank us for our work. Your support helps create employment for local families and restores wildlife habitats.


📄 License

MIT License. See LICENSE for details.


📬 Support


🔄 Changelog

See CHANGELOG.md for recent changes and updates.

devrabiul photo

I am a passionate Software Engineer creating high-quality, error-free websites. I specialize in clean code, performance, security, and user-friendly experiences

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Devrabiul Laravel Geo Genius Related Articles

Honeybadger logo

Honeybadger

Simple developer-focused application monitoring for Laravel. Error tracking, log management, uptime monitoring, status pages, and more!

Honeybadger
Statamic logo

Statamic

The drop-in ready Laravel CMS you’re been waiting for. Go full-stack or headless, flat file or database – it’s up to you.

Statamic
Tighten logo

Tighten

We help companies turn great ideas into amazing apps, products, and services.

Tighten
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel
Securing Laravel logo

Securing Laravel

The essential security resource for Laravel devs, covering everything you need to keep your apps secure. Sign up to receive weekly security tips and monthly in depth articles, diving deep into security concepts you need to know!

Securing Laravel
Celebian logo

Celebian

Celebian is a social media marketing agency specializing in helping their clients go viral on TikTok. Whether you're looking to reach a bigger audience or gain more Tiktok followers, likes, and views, they've got you covered.

Celebian