saeedvaziry/ip2location

IP to Location database
2,933 34
Install
composer require saeedvaziry/ip2location
Latest Version:v0.2.0
PHP:^7.1|^8.0
License:MIT
Last Updated:Sep 26, 2025
Links: GitHub  ·  Packagist
Maintainer: saeedvaziry

Laravel IP2Location Package

StyleCI

IP2Location is a small Laravel package that converts IPs to location.

This package is a wrapper to IP2Location.

Installation

composer require saeedvaziry/ip2location

Configuration

Publish configs with the following command

php artisan vendor:publish --provider="SaeedVaziry\IP2Location\IP2LocationServiceProvider"

Then modify configs/ip2location.php to set your download URL from IP2Location's website

<?php

return [
    'db_path'      => 'database/bin/IP2LOCATION-LITE-DB1.BIN',
    'download_url' => 'https://download.ip2location.com/lite/IP2LOCATION-LITE-DB1.BIN.ZIP',
];

Updating IP database

After the installation, you need to run the following command for updating the IP database.

php artisan ip2location:update

You can also set a scheduler in your app/Console/Kernel.php to keep it up to date.

Usage

Facade

You can use \SaeedVaziry\IP2Location\Facades\IP2Location facade to access to all supported methods.

// returns an array
\SaeedVaziry\IP2Location\Facades\IP2Location::info($ipAddress);

// returns the country full name
\SaeedVaziry\IP2Location\Facades\IP2Location::countryName($ipAddress);

// returns the country 2 character ISO code
\SaeedVaziry\IP2Location\Facades\IP2Location::countryCode($ipAddress);

Helper functions

You may want to access to the methods via helper functions.

// returns an array
ip2location_info($ipAddress);

// returns the country full name
ip2location_country_name($ipAddress);

// returns the country 2 character ISO code
ip2location_country_code($ipAddress);

If you don't pass the $ipAddress in both Facade and Helper, The method will extract the IP address from the Http request.

License

IP2Location is licensed under The MIT License (MIT).

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

631,580,251 9,707
laravel/framework

The Laravel Framework.

580,311,802 34,925
laravel/tinker

Powerful REPL for the Laravel framework.

489,754,436 7,444
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

404,034,618 608
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

384,821,166 4,658