PHPackages                             taylornetwork/geo-ip - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. taylornetwork/geo-ip

ActiveLibrary

taylornetwork/geo-ip
====================

0.1.1(9y ago)014MITPHPPHP &gt;=5.4.0

Since Nov 29Pushed 9y ago1 watchersCompare

[ Source](https://github.com/taylornetwork/laravel-geoip)[ Packagist](https://packagist.org/packages/taylornetwork/geo-ip)[ RSS](/packages/taylornetwork-geo-ip/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

GeoIP for Laravel
=================

[](#geoip-for-laravel)

An easy way to get the location of an IP address in Laravel 5

Install
-------

[](#install)

Via Composer

```
$ composer require tayornetwork/geo-ip
```

Setup
-----

[](#setup)

Register the service provider in the providers array in `config/app.php`

```
'providers' => [

	TaylorNetwork\GeoIP\GeoIPServiceProvider::class,

],
```

---

Add the `GeoIP` facade to the aliases array in `config/app.php`

```
'aliases' => [

	'GeoIP' => TaylorNetwork\GeoIP\Facades\GeoIP::class,

],
```

---

Publish Config

```
$ php artisan vendor:publish
```

Adds `geoip.php` to your `config` folder

Basic Usage
-----------

[](#basic-usage)

### Helper Function

[](#helper-function)

This package comes with a global helper function `geoip` which will return call the `GeoIP` class for you.

Get the location of a specific IP address by passing it to `geoip`

```
geoip('8.8.8.8');

// Returns an object

{#xxx
	+"ip": "8.8.8.8",
	+"country_code": "US",
	+"country_name": "United States",
	+"region_code": "CA",
	+"region_name": "California",
	+"city": "Mountain View",
	+"zip_code": "94035",
	+"time_zone": "America/Los_Angeles",
	+"latitude": 37.386,
	+"longitude": -122.0838,
	+"metro_code": 807,
}
```

Calling `geoip()` with no parameters will return the location of your IP address.

### Class

[](#class)

```
$geoip = new TaylorNetwork\GeoIP\GeoIP ();
```

#### Available Methods

[](#available-methods)

##### findIP (string | null $ip)

[](#findip-string--null-ip)

Usage is identical to helper function (see [Helper Function](#helper-function))

##### makeRequest (string | null $ip)

[](#makerequest-string--null-ip)

Returns the raw response from the HTTP request.

```
$geoip->makeRequest('8.8.8.8');

// Returns

"{"ip":"8.8.8.8","country_code":"US","country_name":"United States","region_code":"CA","region_name":"California","city":"Mountain View","zip_code":"94035","time_zone":"America/Los_Angeles","latitude":37.386,"longitude":-122.0838,"metro_code":807}\n"
```

If called with no parameters, your IP address location is returned.

##### decode (mixed $response)

[](#decode-mixed-response)

Decodes the response given by `$response`.

By default a JSON string is returned (see [makeRequest](#makerequest-string--null-ip)), `decode` will decode the response with `json_decode` to return an object.

```
$response = $geoip->makeRequest('8.8.8.8');

/*
 * We need to remove the newline at the end of the response
 * or decode will fail due to invalid JSON.
 *
 * By default this is done in a driver callback function.
 */
$trimmed = trim($response, "\n");

$geoip->decode($trimmed);

// Returns

{#xxx
	+"ip": "8.8.8.8",
	+"country_code": "US",
	+"country_name": "United States",
	+"region_code": "CA",
	+"region_name": "California",
	+"city": "Mountain View",
	+"zip_code": "94035",
	+"time_zone": "America/Los_Angeles",
	+"latitude": 37.386,
	+"longitude": -122.0838,
	+"metro_code": 807,
}
```

##### getGuzzleClient ()

[](#getguzzleclient-)

Returns an instance of `GuzzleHttp\Client`

##### getDriver ()

[](#getdriver-)

Returns an instance of the driver, by default `FreeGeoIP`

See [Drivers](#drivers)

### Facade

[](#facade)

```
GeoIP::findIP()
```

All methods in the class are available with the facade. (see [Class](#class))

Drivers
-------

[](#drivers)

This package comes with a FreeGeoIP driver by default. However you can use any custom driver you want with this package.

To create a new driver run

```
$ php artisan geoip:driver DriverName
```

This will generate a driver class in `App\GeoIP\Drivers`

**To use a driver, it MUST be registered in `config/geoip.php`**

A driver class will look something like this.

```
namespace App\GeoIP\Drivers;

use TaylorNetwork\GeoIP\Drivers\Driver;

class DriverName extends Driver
{
    /**
     * Driver Definition
     *
     * Set all required properties here.
     *
     * @return void
     */
    public function define ()
    {
        $this->name = 'DriverName';
        $this->method = 'GET';
        $this->URL = 'http://driver-url.com';
        $this->responseType = 'JSON';
    }
}
```

*All properties in the define() function must be set to a non empty value*

### Override Methods

[](#override-methods)

If you want to use your own function to find an IP address, or need to format the response after an HTTP request you can override these methods in your driver.

#### responseCallback (mixed $response)

[](#responsecallback-mixed-response)

Called after an HTTP request, but before passing to the `GeoIP` decode function (see [Decode](#decode-mixed-response))

```
public function responseCallback($response)
{
	// Code to format, etc.

	return $response;
}
```

#### findIP (string | null $ip)

[](#findip-string--null-ip-1)

Called when `findIP` is called from class. If `false` is returned, `GeoIP` will do the work. If not the response is then passed to `responseCallback` and then `decode`

```
public function findIP ($ip = null)
{
	// Code to do HTTP request, and get response...

	return $response;
}
```

### Available Methods

[](#available-methods-1)

#### property (string $key)

[](#property-string-key)

Returns a driver property.

```
$driver->property('name');

// Returns

'DriverName'
```

#### properties ()

[](#properties-)

Returns all driver properties in an associative array.

Credits
-------

[](#credits)

- Author: [Sam Taylor](https://github.com/taylornetwork)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

3451d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/83340094473f0bf5b2cf062bf394df221a52a30aa0e21cd0a77302977d6393ce?d=identicon)[samueljtaylor](/maintainers/samueljtaylor)

---

Top Contributors

[![samyrataylor](https://avatars.githubusercontent.com/u/15961687?v=4)](https://github.com/samyrataylor "samyrataylor (3 commits)")

### Embed Badge

![Health badge](/badges/taylornetwork-geo-ip/health.svg)

```
[![Health](https://phpackages.com/badges/taylornetwork-geo-ip/health.svg)](https://phpackages.com/packages/taylornetwork-geo-ip)
```

###  Alternatives

[vemcogroup/laravel-sparkpost-driver

SparkPost driver to use with Laravel 6.x|7.x|8.x|9.x|10.x

421.7M1](/packages/vemcogroup-laravel-sparkpost-driver)[scriptdevelop/whatsapp-manager

Paquete para manejo de WhatsApp Business API en Laravel

762.6k](/packages/scriptdevelop-whatsapp-manager)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
