承接 jord-jd/laravel-geolocation-request 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

jord-jd/laravel-geolocation-request

最新稳定版本:v2.0.0

Composer 安装命令:

composer require jord-jd/laravel-geolocation-request

包简介

Laravel Geolocation Request

README 文档

README

The Laravel Geolocation Request package provides an easy way to geolocate requests to their country of origin, simply by calling a $request->country() method.

Installation

To install the Laravel Geolocation Request package, just run the following Composer command.

composer require jord-jd/laravel-geolocation-request

Usage

To use geolocation enabled requests within your Laravel controller methods, you can replace the use Illuminate\Http\Request line at the top of your controllers, as shown in the usage example below.

Once done, you can simple call the $request->country() method to perform geolocation and return the origin country of the active request based on its IP address. The country is returned as an object containing many properties, such as the country name and ISO codes.

<?php

namespace App\Http\Controllers;

//use Illuminate\Http\Request;
use JordJD\LaravelGeolocationRequest\Http\Requests\GeolocationRequest as Request;

class UserController extends Controller
{
    /**
     * Store a new user.
     *
     * @param  Request  $request
     * @return Response
     */
    public function store(Request $request)
    {
        // Perform geolocation, and return a country object.
        $country = $request->country();
        
        $user = new \App\User();
        $user->name = $request->name;
        $user->countryName = $country->name;
        $user->countryCode = $country->isoCodeAlpha3;
        
        $user->save();
        
        // ...
    }
}

If you are using custom request objects, you can change them to extend the provided GeolocationRequest class. If you unable to extend your custom request object, or simply do not wish to, you can add geolocation functionality by using the provided GeolocatableRequest trait.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: LGPL-3.0-only
  • 更新时间: 2026-02-14