PHPackages                             oravil/laravel-guard - 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. [Security](/categories/security)
4. /
5. oravil/laravel-guard

ActiveLibrary[Security](/categories/security)

oravil/laravel-guard
====================

laravel geo location, ip services, proxy and vpn detected

1.2.1(4y ago)49341[1 issues](https://github.com/oravil/laravel-guard/issues)MITPHPPHP ^8.0

Since Nov 5Pushed 4y ago1 watchersCompare

[ Source](https://github.com/oravil/laravel-guard)[ Packagist](https://packagist.org/packages/oravil/laravel-guard)[ Docs](https://github.com/oravil/laravel-guard)[ GitHub Sponsors](https://github.com/oravil)[ RSS](/packages/oravil-laravel-guard/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (2)Dependencies (11)Versions (4)Used By (0)

laravel geo location, ip services, proxy and vpn detected
=========================================================

[](#laravel-geo-location-ip-services-proxy-and-vpn-detected)

[![Latest Version on Packagist](https://camo.githubusercontent.com/031419c0adabda5bfb4234e1a5ea24e1b1dfc3ca1ac24a61bbdf5bb834a05467/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f726176696c2f6c61726176656c2d67756172642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/oravil/laravel-guard)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/2c2018769202a582b3169c4a7bd97576af4c2d64021bfdd2d18498e6edee4882/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6f726176696c2f6c61726176656c2d67756172642f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/oravil/laravel-guard/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/00b67843107cf67c3d62959da0d5d31349d6a1235e9848748fdc6762ad732878/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f726176696c2f6c61726176656c2d67756172642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/oravil/laravel-guard)[![Donate](https://camo.githubusercontent.com/031419c0adabda5bfb4234e1a5ea24e1b1dfc3ca1ac24a61bbdf5bb834a05467/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f726176696c2f6c61726176656c2d67756172642e7376673f7374796c653d666c61742d737175617265)](https://paypal.me/AhmdYehia)

---

Package Support
===============

[](#package-support)

- [laravel 8](https://laravel.com)
- [php 8](https://www.php.net/releases/8.0/en.php)
- [IpRegistry ](https://ipregistry.co)
- [IpInfo](https://ipinfo.io)
- [IpData](https://ipdata.co)
- [Ip-Api](https://ip-api.com)
- [Ip-Api-Pro](https://ip-api.com)
- [IpApi.com](https://ipapi.com)
- [IpHub](https://iphub.info)
- [ProxyCheck](https://proxycheck.io)
- [GeoPlugin](http://www.geoplugin.net)
- [ipgeolocation](https://ipgeolocation.io)
- [MaxMind - database](https://www.maxmind.com)
- [MaxMind - api](https://www.maxmind.com)

Providers Features
------------------

[](#providers-features)

ProviderRequire ApiFree LimitPaid LimitSupport LanguagesSupport SecuritySupport CurrenicesSupport LocationIpHub✔1k/dayup to 200k/day❌❌❌✔IpRegistry✔100k/oncePer Paid Package✔✔✔✔Ip-Api❌45/minuteunlimited❌✔❌✔IpInfo✔50k/monthup to 2.5m/month❌✔❌✔IpData✔1.5k/dayup to 100k/day✔✔✔✔IpApi.com✔1k/monthup to 2m/month✔✔✔✔ProxyCheck❌1k/dayup to 10m/day❌✔❌✔GeoPlugin❌Unknown❌❌❌✔✔IpGeoLocation✔1k/dayup to 20m/month✔❌✔✔---

This package can be used to handle all ip services as a Laravel package. It Can Help With:

1. Determine the geographical location of website visitors based on their IP addresses
2. Detected Vpn, Proxy, Tor and Hosting Ip's.
3. retrieve Language, Currencies and Location Data.
4. Block connections via Connections Type Filters.
5. Cache ip data in cache drivers
6. Block Connections by country(dev).

Support us
----------

[](#support-us)

[buy me a coffee](https://paypal.me/AhmdYehia)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require oravil/laravel-guard
```

You can publish the config file with:

```
php artisan vendor:publish --provider="Oravil\LaravelGuard\LaravelGuardServiceProvider"
```

This is the contents of the published config file:

```
// config for Oravil/LaravelGuard config/guard.php
return [
    // laravel guard version
    'version' => '1.2',

    /*
    |-------------------------------------------------------------------------
    | Cache Driver
    | To use cache tags you should support one of cache drivers Redis / Memcached / Array
    |-------------------------------------------------------------------------
     *
     */

    'cache_enable' => false, // set true to enable cache

    'cache_tag_name' => 'lg-location', // cache tag name

    'cache_expires' => 30, // seconds

    /*
    |--------------------------------------------------------------------------
    | Provider
    |--------------------------------------------------------------------------
    |
    | The default provider you would like to use for geo ip retrieval.
    |
    */

    'provider' => 'ip-api',

    /*
    |--------------------------------------------------------------------------
    | Driver Fallbacks
    |--------------------------------------------------------------------------
    |
    | The providers you want to use to retrieve the users geo ip
    | if the above selected driver is unavailable.
    |
    | These will be called upon in order (first to last).
    |
    */

    'fallbacks' => [
        Oravil\LaravelGuard\Providers\IpRegistry::class,
        Oravil\LaravelGuard\Providers\IpApi::class,
    ],

    /*
    |--------------------------------------------------------------------------
    | Location
    |--------------------------------------------------------------------------
    |
    | Here you may configure the position instance that is created
    | and returned from the above drivers. The instance you
    | create must extend the built-in Position class.
    |
    */

    'location' => Oravil\LaravelGuard\Support\Location::class,

    /*
    |--------------------------------------------------------------------------
    | Localhost Testing
    |--------------------------------------------------------------------------
    |
    | If your running your website locally and want to test different
    | IP addresses to see location detection, set 'enabled' to true.
    |
    | The testing IP address is a Google host in the United-States.
    |
    */

    'testing' => [
        'enabled'  => env('GUARD_TESTING', false),
        'valid_ip' => '102.189.209.97',
        'cloud_ip' => '108.162.193.194',
        'proxy_ip' => '193.176.86.46',
        'tor_ip'   => '103.236.201.88',
        'bogon_ip' => '203.0.113.24',
    ],

    /*
    |--------------------------------------------------------------------------
    | Security Filters
    |--------------------------------------------------------------------------
    |
    |
    |
    */

    'security' => [
        'enabled' => env('GUARD_SECURITY', false),
        'middleware' => [
            //\Oravil\LaravelGuard\ShouldBlockMiddleware::class, copy to Http/kernel.php
            'enabled' => false,
            'block_message' => 'Your connection has been blocked, Our system has identified you as a threa',
            'abort_code' => 403
        ],
        'filters' => [
            'is_cloud' => true,
            'is_anonymous' => true,
            'is_threat' => true,
            'is_bogon' => true,
        ]
    ],

    /*
    |--------------------------------------------------------------------------
    | Providers List Configure
    |--------------------------------------------------------------------------
    |
    |
    |
    */

    'providers' => [
        'ipregistry' => [  // ip registry https://ipregistry.co/docs/
            'class' => \Oravil\LaravelGuard\Providers\IpRegistry::class, //provider class path
            'api_key' => env('IPREGISTRY_API_KEY', null), // api key
            'api_url' => 'https://api.ipregistry.co/', // api base url
            'currencies_enabled' => env('GUARD_CURRENCIES', true), // if you need currencies data
            'language_enabled' => env('GUARD_LANGUAGE', true), // if you need langauge data
            'security_enabled' => env('GUARD_SECURITY', true), //security status
        ],

        'iphub' => [ // ip hub https://iphub.info/
            'class' => \Oravil\LaravelGuard\Providers\IpHub::class, //provider class path
            'api_key' => env('IPHUB_API_KEY', null), // api key
            'api_url' => 'http://v2.api.iphub.info/ip/', // api base url
            'security_enabled' => env('GUARD_SECURITY', true), //security status
        ],

        'ip-api' => [ // ip api https://ip-api.com/
            'class' => \Oravil\LaravelGuard\Providers\IpApi::class, //provider class path
            'pro_api_url' => 'https://pro.ip-api.com/json/', // pro services
            'api_key' => env('IPAPI_API_KEY', null), // api key
            'api_url' => 'http://ip-api.com/json/', // api base url
            'currencies_enabled' => true, //  support currenices code only
            'security_enabled' => env('GUARD_SECURITY', true), //security status
        ],

        'proxycheck' => [ // ip api https://proxycheck.io/
            'class' => \Oravil\LaravelGuard\Providers\ProxyCheck::class, //provider class path
            'api_key' => env('PROXYCHECK_API_KEY', null), // api key
            'api_url' => 'http://proxycheck.io/v2/', // api base url
            'security_enabled' => env('GUARD_SECURITY', true), //security status
            'block_score' => 33
        ],

        'ipapicom' => [ // ip api https://ipapi.com/
            'class' => \Oravil\LaravelGuard\Providers\IpApiCom::class, //provider class path
            'api_key' => env('IPAPICOM_API_KEY', null), // api key
            'api_url' => 'http://api.ipapi.com/api/', // api base url
            'security_enabled' => env('GUARD_SECURITY', false), //security status
            'security_plan_enable' => false, // if you plan is BUSINESS PRO
            'currency_plan_enable' => false, // if you plan is STANDARD or above
        ],

        'ipdata' => [ // ip data https://ipdata.co/
            'class' => \Oravil\LaravelGuard\Providers\IpData::class, //provider class path
            'api_key' => env('IPDATA_API_KEY', null), // api key
            'api_url' => 'https://api.ipdata.co/', // api base url
            'currencies_enabled' => env('GUARD_CURRENCIES', true), // if you need currencies data
            'language_enabled' => env('GUARD_LANGUAGE', true), // if you need langauge data
            'security_enabled' => env('GUARD_SECURITY', true), //security status
        ],

        'ipinfo' => [ // ip data https://ipdata.co/
            'class' => \Oravil\LaravelGuard\Providers\IpInfo::class, //provider class path
            'api_key' => env('IPINFO_API_KEY', null), // api key
            'api_url' => '//ipinfo.io/', // api base url
            'security_enabled' => env('GUARD_SECURITY', true), //security status
        ],

        'geoplugin' => [ // ip data http://www.geoplugin.net
            'class' => \Oravil\LaravelGuard\Providers\GeoPlugin::class, //provider class path
            'api_url' => 'http://www.geoplugin.net/json.gp?ip', // api base url
            'currencies_enabled' => env('GUARD_CURRENCIES', true), // if you need currencies data
        ],

        'ipgeolocation' => [ // ip data https://ipgeolocation.io
            'class' => \Oravil\LaravelGuard\Providers\IpGeoLocation::class, //provider class path
            'api_key' => env('IP_GEO_LOCATION_API_KEY', null), // api key
            'api_url' => 'https://api.ipgeolocation.io/ipgeo', // api base url
            'currencies_enabled' => env('GUARD_CURRENCIES', true), // if you need currencies data
            'language_enabled' => env('GUARD_LANGUAGE', true), // if you need langauge data
        ],
    ],
];
```

Usage
-----

[](#usage)

```
#global functions
echo getIp();                                    // get location instance for client ip | testing ip if testing_enable => true
echo getIp('8.8.8.8');                           // LaravelGuard::get('8.8.8.8');
echo laravelGuard('8.8.8.8');                    // LaravelGuard::get('8.8.8.8');
echo laravelGuard()->echoApiResponse('8.8.8.8'); // LaravelGuard::echoApiResponse('8.8.8.8');
echo laravelGuard()->echoApiResponse();          // LaravelGuard::echoApiResponse('8.8.8.8');
echo laravelGuard()->testing('type');            // testing connection type(valid, proxy, vpn, tor, cloud, bogon), default: valid
laravelGuard()->flushCache();                    // flushed locations cache
//laravel facade
use Oravi/LaravelGuard/Facades/LaravelGuard;
echo LaravelGuard::get();                        // get location instance for client ip | testing ip if testing_enable => true
echo LaravelGuard::get('8.8.8.8');               // get location instance
echo LaravelGuard::echoApiResponse('8.8.8.8');   // get request from api for client ip
echo LaravelGuard::echoApiResponse();   // get request from api for client ip | testing ip if testing_enable => true
echo LaravelGuard::testing('type');              // testing connection type(valid, proxy, vpn, tor, cloud, bogon), default: valid
LaravelGuard::flushCache();                      // flushed locations cache
```

Security Filters
----------------

[](#security-filters)

```
// app/http/kernel.php
protected $middleware = [
    ...
    \Oravil\LaravelGuard\ShouldBlockMiddleware::class
];

//config/guard.php
'security' => [
        'enabled' => env('GUARD_SECURITY', true), //set true to enable security filters
        'middleware' => [
            //\Oravil\LaravelGuard\ShouldBlockMiddleware::class, copy to Http/kernel.php
            'enabled' => true, // set true to enable middleware
            'block_message' => 'Your connection has been blocked, Our system has identified you as a threa', //edit block message
            'abort_code' => 403 //edit abort code
        ],
        'filters' => [
            'is_cloud' => true,
            'is_anonymous' => true,
            'is_threat' => true,
            'is_bogon' => true,
        ]
    ],
```

to retrive ip data from middleware without block connection
===========================================================

[](#to-retrive-ip-data-from-middleware-without-block-connection)

```
// set security true
'middleware' => [
    //\Oravil\LaravelGuard\ShouldBlockMiddleware::class, copy to Http/kernel.php
    'enabled' => false, // set false to disable block connections
    ....
]
// get ip data
dd(request()->ipGuard);
//check should block connection
dd(request()->ipGuard->shouldBlock);
// check block type
dd(request()->ipGuard->blockType);
```

Testing
-------

[](#testing)

```
// testing using ipregistry provider
return laravelGuard()->testing(); // or laravelGuard()->testing('valid');
//output: {"ip":"102.189.209.97","countryName":"Egypt","countryCode":"EG","regionCode":"EG-C","regionName":"Al Q\u0101hirah","cityName":"Cairo","zipCode":"09893","latitude":"30.07795","longitude":"31.28525","areaCode":1001450,"isEU":false,"currencyStatus":true,"currencyName":"Egyptian Pound","currencyCode":"EGP","currencySymbol":"EGP","langStatus":true,"langName":"Arabic","langNative":"\u0627\u0644\u0639\u0631\u0628\u064a\u0629","langCode":"ar","timeZone":"Africa\/Cairo","currentTime":"2021-11-05T06:57:33+02:00","securityStatus":true,"isCloudProvider":false,"isThreat":false,"isAnonymous":false,"isBogon":false,"provider":"IpRegistry","provider_class":"Oravil\\LaravelGuard\\Providers\\IpRegistry","isCached":null}

return laravelGuard()->testing('cloud');
// output: {"ip":"108.162.193.194","countryName":"United States","countryCode":"US","regionCode":null,"regionName":null,"cityName":null,"zipCode":null,"latitude":"37.75096","longitude":"-97.822","areaCode":9629091,"isEU":false,"currencyStatus":true,"currencyName":"US Dollar","currencyCode":"USD","currencySymbol":"$","langStatus":true,"langName":"English","langNative":"English","langCode":"en","timeZone":"America\/Chicago","currentTime":"2021-11-04T23:59:59-05:00","securityStatus":true,"isCloudProvider":true,"isThreat":false,"isAnonymous":false,"isBogon":false,"provider":"IpRegistry","provider_class":"Oravil\\LaravelGuard\\Providers\\IpRegistry","isCached":null}

return laravelGuard()->testing('proxy'); // or laravelGuard()->testing('vpn');
//output: {"ip":"193.176.86.46","countryName":"Germany","countryCode":"DE","regionCode":"DE-BE","regionName":"Berlin","cityName":"Berlin","zipCode":"10178","latitude":"52.51965","longitude":"13.40687","areaCode":357021,"isEU":true,"currencyStatus":true,"currencyName":"Euro","currencyCode":"EUR","currencySymbol":"\u20ac","langStatus":true,"langName":"German","langNative":"Deutsch","langCode":"de","timeZone":"Europe\/Berlin","currentTime":"2021-11-05T06:00:43+01:00","securityStatus":true,"isCloudProvider":false,"isThreat":true,"isAnonymous":false,"isBogon":false,"provider":"IpRegistry","provider_class":"Oravil\\LaravelGuard\\Providers\\IpRegistry","isCached":null}

return laravelGuard()->testing('tor')
//output: {"ip":"103.236.201.88","countryName":"Indonesia","countryCode":"ID","regionCode":"ID-BT","regionName":"Banten","cityName":"Tangerang","zipCode":null,"latitude":"-6.17836","longitude":"106.63184","areaCode":1919440,"isEU":false,"currencyStatus":true,"currencyName":"Indonesian Rupiah","currencyCode":"IDR","currencySymbol":"IDR","langStatus":true,"langName":"Indonesian","langNative":"Indonesia","langCode":"id","timeZone":"Asia\/Jakarta","currentTime":"2021-11-05T12:02:37+07:00","securityStatus":true,"isCloudProvider":true,"isThreat":true,"isAnonymous":true,"isBogon":false,"provider":"IpRegistry","provider_class":"Oravil\\LaravelGuard\\Providers\\IpRegistry","isCached":null}

return laravelGuard()->testing('bogon')
//output: {"ip":"203.0.113.24","countryName":null,"countryCode":null,"regionCode":null,"regionName":null,"cityName":null,"zipCode":null,"latitude":"-4.0E-5","longitude":"4.0E-5","areaCode":0,"isEU":false,"currencyStatus":true,"currencyName":null,"currencyCode":null,"currencySymbol":null,"langStatus":true,"langName":null,"langNative":null,"langCode":null,"timeZone":"Africa\/Sao_Tome","currentTime":"2021-11-05T05:03:28Z","securityStatus":true,"isCloudProvider":false,"isThreat":true,"isAnonymous":false,"isBogon":true,"provider":"IpRegistry","provider_class":"Oravil\\LaravelGuard\\Providers\\IpRegistry","isCached":null}
```

Flushed locations cache
=======================

[](#flushed-locations-cache)

// console

```
php artisan guard:flush
```

//php

```
return laravelGuard()->flushCache();
```

Todo
----

[](#todo)

- add api service providers.
- push to Github
- push Pre-release
- add to Packagist
- add cache driver
- add cache flush console command
- add global functions
- push version 1.1
- block connections via filters
- block connections via midlleware
- push version 1.2
- add create custom provider console command
- push version 1.3
- add fallbacks for limit requests
- add github documentation
- push version 2.0

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Thanks To:
----------

[](#thanks-to)

- [Torann](https://github.com/Torann/laravel-geoip)
- [Stevebauman](https://github.com/stevebauman/location)

Credits
-------

[](#credits)

- [AhmdYehia](https://github.com/oravil)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity57

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 ~1 days

Total

3

Last Release

1648d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e2438728e583a786446f36d50b50b0c9f44683d394233bc277e2a940a8c6ab81?d=identicon)[Oravil](/maintainers/Oravil)

---

Top Contributors

[![oravil](https://avatars.githubusercontent.com/u/59480892?v=4)](https://github.com/oravil "oravil (34 commits)")

---

Tags

laravelproxysecuritymaxmindlocationgeotorguardIP APIinfoDBIP Infovpnip registry

###  Code Quality

TestsPest

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/oravil-laravel-guard/health.svg)

```
[![Health](https://phpackages.com/badges/oravil-laravel-guard/health.svg)](https://phpackages.com/packages/oravil-laravel-guard)
```

###  Alternatives

[spatie/laravel-ciphersweet

Use ciphersweet in your Laravel project

416718.4k1](/packages/spatie-laravel-ciphersweet)[akaunting/laravel-firewall

Web Application Firewall (WAF) package for Laravel

999465.8k2](/packages/akaunting-laravel-firewall)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[dgtlss/warden

A Laravel package that proactively monitors your dependencies for security vulnerabilities by running automated composer audits and sending notifications via webhooks and email

8745.6k](/packages/dgtlss-warden)[muhammadhuzaifa/telescope-guzzle-watcher

Telescope Guzzle Watcher provide a custom watcher for intercepting http requests made via guzzlehttp/guzzle php library. The package uses the on\_stats request option for extracting the request/response data. The watcher intercept and log the request into the Laravel Telescope HTTP Client Watcher.

98239.8k1](/packages/muhammadhuzaifa-telescope-guzzle-watcher)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)

PHPackages © 2026

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