An open API service indexing awesome lists of open source software.

https://github.com/devrabiul/laravel-geo-genius

🌍 Laravel GeoGenius β€” IP-based geolocation, timezone, multilingual toolkit + country picker & phone validation for Laravel apps
https://github.com/devrabiul/laravel-geo-genius

country-picker geolocation laravel multilingual package timezone user-timezone

Last synced: 25 days ago
JSON representation

🌍 Laravel GeoGenius β€” IP-based geolocation, timezone, multilingual toolkit + country picker & phone validation for Laravel apps

Awesome Lists containing this project

README

          

# πŸ“¦ 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**.

[![Latest Stable Version](https://poser.pugx.org/devrabiul/laravel-geo-genius/v/stable)](https://packagist.org/packages/devrabiul/laravel-geo-genius)
[![Total Downloads](https://poser.pugx.org/devrabiul/laravel-geo-genius/downloads)](https://packagist.org/packages/devrabiul/laravel-geo-genius)
[![Monthly Downloads](https://poser.pugx.org/devrabiul/laravel-geo-genius/d/monthly)](https://packagist.org/packages/devrabiul/laravel-geo-genius)
![GitHub license](https://img.shields.io/github/license/devrabiul/laravel-geo-genius)
[![Buy us a tree](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-lightgreen)](https://plant.treeware.earth/devrabiul/laravel-geo-genius)
![GitHub Repo stars](https://img.shields.io/github/stars/devrabiul/laravel-geo-genius?style=social)

---

## πŸš€ Live Demo

πŸ‘‰ [Try the Live Demo](https://packages.rixetbd.com/laravel-geo-genius)

![Live Demo Thumbnail](https://packages.rixetbd.com/storage/app/public/package/devrabiul/laravel-geo-genius.webp)

---

## ✨ 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`](https://ipwho.is) and [`ip-api.com`](http://ip-api.com) with caching for optimal performance.

---

## πŸ“¦ Installation

```bash
composer require devrabiul/laravel-geo-genius
```

Publish the configuration and migration stub:

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

---

## ⚑ Quick Start

Use Laravel GeoGenius in two ways:

1. βœ… **Global Helper** β€” `laravelGeoGenius()` *(recommended)*
2. 🧰 **Service Class** β€” manually instantiate `GeoLocationService`

### Global Helper

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

### Service Class

```php
use Devrabiul\LaravelGeoGenius\Services\GeoLocationService;

$geo = new GeoLocationService();

$ip = $geo->getClientIp();
$locationData = $geo->locateVisitor();
```

---

## 🌐 Multilingual & Translation

Built-in auto translation and number conversion:

```php
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`:

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

## 🌐 Change Current User Language

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

```php
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

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

---

## πŸ•’ Timezone Detection & Conversion

```php
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

```bash
# 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

```html


// must be use type="tel" in your phone input


// Before Body close tag
{!! laravelGeoGenius()->initIntlPhoneInput() !!}

```

GeoGenius injects the detected country code into a hidden span:

```html

```

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

```js
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 `` and optionally the validation snippet.

---

## 🧠 Additional Notes

* 🌐 **APIs Used:** [ipify.org](https://api.ipify.org), [ipwho.is](https://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](https://github.com/devrabiul/laravel-geo-genius/issues).

---

## 🌱 Treeware

This package is [Treeware](https://treeware.earth). If you use it in production, please [**buy the world a tree**](https://plant.treeware.earth/devrabiul/laravel-geo-genius) to thank us for our work. Your support helps create employment for local families and restores wildlife habitats.

---

## πŸ“„ License

MIT License. See [LICENSE](https://github.com/devrabiul/laravel-geo-genius/blob/main/LICENSE) for details.

---

## πŸ“¬ Support

- πŸ“§ Email: [devrabiul@gmail.com](mailto:devrabiul@gmail.com)
- 🌐 GitHub: [devrabiul/laravel-geo-genius](https://github.com/devrabiul/laravel-geo-genius)
- πŸ“¦ Packagist: [packagist.org/packages/devrabiul/laravel-geo-genius](https://packagist.org/packages/devrabiul/laravel-geo-genius)

---

## πŸ”„ Changelog

See [CHANGELOG.md](https://github.com/devrabiul/laravel-geo-genius/blob/main/CHANGELOG.md) for recent changes and updates.