定制 palauaandsons/cloudflare-geoip 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

palauaandsons/cloudflare-geoip

最新稳定版本:1.1.1

Composer 安装命令:

composer require palauaandsons/cloudflare-geoip

包简介

Cloudflare GeoIP helper with Laravel

README 文档

README

Get the geographical localtion of visitor based off Cloudflare headers.

Caution

Make sure Visitor Location & IP Geolocation are enabled in Cloudflare Dashboard.

Installation

composer require palauaandsons/cloudflare-geoip

Configuration

Run the following command to publish configuration. Be sure to modify the configuration file specifically the default location to use if the cloudflare headers are absent.

php artisan vendor:publish --tag=cloudflare-geoip-config

Usage

<?php

namespace App\Http\Controllers;

use PalauaAndSons\CloudflareGeoIp\Facades\GeoIp;
use App\Models\Users;

class RegisterController extends Controller {
    public function __invoke(): User
    {
        $location = GeoIp::getLocation();

        return User::create([
            'register_ip' => $location->ip
        ]);
    }
}

Location Object

\PalauaAndSons\CloudflareGeoIp\Location {
    +ip: "192.182.88.29"
    +city: "New Haven"
    +country: "US"
    +continent: "NA"
    +latitude: 41.31
    +longitude: -72.92
    +postalCode: "06510"
    +region: "Connecticut"
    +regionCode: "CT"
    +timezone: "America/New_York"
    // pseudo fields
    +iso_code: 'US' // same as country
    +isoCode: 'US' // same as country
    +state: 'CT' // same as regionCode
    +state_name: 'Connecticut' // same as region
    +stateName: 'Connecticut' // same as region
    +postal_code: '06510' // same as postal_code
    +lat: '41.31' // same as latitude
    +lon: -72.92 // same as longitude

    +toArray(): array
}

统计信息

  • 总下载量: 4.41k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-15