cslash/laravel-geoname
最新稳定版本:1.0.0
Composer 安装命令:
composer require cslash/laravel-geoname
包简介
Generate location labels like FR-WEST from IP addresses in Laravel.
README 文档
README
Laravel GeoName is a lightweight package that generates location labels (e.g., FR-WEST, US-CENTRAL) from IP addresses or geographic coordinates.
It's built on top of stevebauman/location to provide regional resolution.
Requirements
- PHP 8.2 or higher
- Laravel 10.0 or higher
Installation
You can install the package via composer:
composer require cslash/laravel-geo-name
The package will automatically register its service provider and facade.
Optionally, you can publish the config file:
php artisan vendor:publish --tag="geoname-config"
Usage
Using the Facade
The GeoName facade provides a simple interface to resolve location labels.
From Current Request
Automatically detect the user's IP address from the current request:
use Cslash\GeoName\Facades\GeoName; $label = GeoName::fromRequest(); // Returns something like "FR-NORTH" or "US-WEST"
From a Specific IP
use Cslash\GeoName\Facades\GeoName; $label = GeoName::fromIp('8.8.8.8');
From GeoContext
If you already have coordinates or region data, you can use a GeoContext object:
use Cslash\GeoName\Data\GeoContext; use Cslash\GeoName\Facades\GeoName; $context = new GeoContext( countryCode: 'FR', regionName: 'Brittany', regionCode: 'BRE', latitude: 48.1173, longitude: -1.6778 ); $label = GeoName::fromContext($context); // "FR-WEST"
Configuration
The config/geoname.php file allows you to customize fallbacks and region mappings:
return [ 'fallback' => 'XX-UNKNOWN', // Returned when IP location cannot be determined 'unknown_zone' => 'UNKNOWN', // Returned when coordinates are missing for generic resolution 'countries' => [ 'FR' => [ 'thresholds' => [47.5, 44.5, -0.5, 4.5], // north, south, west, east 'region_map' => [ 'BRE' => 'WEST', 'NOR' => 'WEST', // ... ], ], ], ];
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-27