| Recommend this page to a friend! | 
| Info | Documentation | Reputation | Support forum | Blog | Links | 
| Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
| 2025-04-22 (Yesterday)  | Not yet rated by the users | Total: Not yet counted | Not yet ranked | |||||
| Version | License | PHP version | Categories | |||
| laraguard-ip 1.0 | BSD License | 7 | Libraries, Security, PHP 7 | 
| Description | Author  | |
This package can block HTTP requests from spamming IP addresses.  | 
Please read this instructions document to learn how to configure this package and use it in Laravel applications to block requests from IP addresses used to spam your site.
<p align="center">
<img src="laraguard-ip-logo.png" alt="laraguard-ip Logo" style="width: 100%; max-width: 800px;" />
</p> <h1>? Laraguard-IP</h1>
A powerful Laravel package to protect your application using IP-based, country-based, and spam-blacklist-based middleware. <p align="center"> <a href="https://packagist.org/packages/haxneeraj/laraguard-ip"><img src="https://img.shields.io/packagist/dt/haxneeraj/laraguard-ip" alt="Total Downloads"></a> <a href="https://packagist.org/packages/haxneeraj/laraguard-ip"><img src="https://img.shields.io/packagist/v/haxneeraj/laraguard-ip" alt="Latest Stable Version"></a> <a href="https://packagist.org/packages/haxneeraj/laraguard-ip"><img src="https://img.shields.io/packagist/l/haxneeraj/laraguard-ip" alt="License"></a> </p>
> Created with ?? by Neeraj Saini _(opens in new tab)_
composer require haxneeraj/laraguard-ip
Add the service provider to the config/app.php file (this step may be optional if you're using Laravel's package auto-discovery):
For Laravel 10 and below:
    'providers' => [
        // Other service providers...
        Haxneeraj\LaraguardIp\Providers\LaraguardIpServiceProvider::class,
    ],
For Laravel 11:
Add the service provider to the bootstrap/providers.php file (this step may be optional if you're using Laravel's package auto-discovery):
    return [
        // Other service providers...
        Haxneeraj\LaraguardIp\Providers\LaraguardIpServiceProvider::class,
    ];
php artisan vendor:publish --provider="Haxneeraj\LaraguardIp\Providers\LaraguardIpServiceProvider" --tag=config
This will create a config file at:
config/laraguard-ip.php
The middleware is automatically registered via the package's service provider. You can directly use it in your routes like this:
Route::middleware(['laraguard-ip'])->group(function () {
    // Protected routes
});
Here's a summary of available config values:
| Key                           | Description                         | Default                                     |
| ----------------------------- | ----------------------------------- | ------------------------------------------- |
| laraguardip_spam_protection | Enable blocklist protection         | false                                     |
| whitelist_only_access       | Only allow IPs in whitelist_ips   | false                                     |
| country_whitelist_only      | Only allow from country_whitelist | false                                     |
| whitelist_ips               | Safe IPs                            | ['127.0.0.1']                             |
| country_whitelist           | Allowed ISO country codes           | ['IN', 'US']                              |
| sources                     | Blocklist sources (URL)             | AbuseIPDB                                   |
| path                        | Blocklist storage path              | storage/framework/cache/laraguard-ip.json |
| compress                    | Enable IP compression               | true                                      |
You can fetch and store the latest spam IPs from the defined sources:
php artisan laraguardip:update
.envLARAGUARDIP_SPAM_PROTECTION=true
LARAGUARDIP_WHITELIST_ONLY=false
LARAGUARDIP_COUNTRY_WHITELIST_ONLY=false
LARAGUARDIP_STORAGE_PATH=framework/cache/laraguard-ip.json
LARAGUARDIP_STORAGE_COMPRESS=true
This package comes with feature and unit tests to ensure everything works smoothly.
composer test
Pull requests are welcome! Feel free to fork, raise issues or drop ideas.
MIT © Neeraj Saini _(opens in new tab)_
| File | Role | Description | ||
|---|---|---|---|---|
| Data | Auxiliary data | |||
| Data | Auxiliary data | |||
| Icon | Icon image | |||
| Data | Auxiliary data | |||
| Doc. | Documentation | |||
| / | src | / | Console | / | Commands | 
| File | Role | Description | 
|---|---|---|
|    | 
Class | Class source | 
| / | src | / | Http | / | Middleware | 
| File | Role | Description | 
|---|---|---|
|    | 
Class | Class source | 
| / | src | / | Providers | 
| File | Role | Description | 
|---|---|---|
|    | 
Class | Class source | 
| / | tests | / | Feature | 
| File | Role | Description | 
|---|---|---|
|    | 
Class | Class source | 
|    | 
Class | Class source | 
| The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. | 
| Version Control | Unique User Downloads | |||||||
| 100% | 
  | 
| Applications that use this package | 
 If you know an application of this package, send a message to the author to add a link here.