PHPackages                             xultech/laravel-ip-whitelist - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. xultech/laravel-ip-whitelist

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

xultech/laravel-ip-whitelist
============================

Laravel middleware package for IP whitelisting with CIDR and wildcard support.

v1.0.1(1y ago)17MITPHPPHP &gt;=7.4

Since Mar 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Xultech-LTD/laravel-ip-whitelist)[ Packagist](https://packagist.org/packages/xultech/laravel-ip-whitelist)[ RSS](/packages/xultech-laravel-ip-whitelist/feed)WikiDiscussions main Synced 1mo ago

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

Laravel IP Whitelist
====================

[](#laravel-ip-whitelist)

A flexible, modern Laravel middleware package to protect your application using configurable IP whitelisting. Supports CIDR blocks, wildcards, exact IPs, and storage via config or database.

---

✨ Features
----------

[](#-features)

- ✅ Match IPs using:
    - Exact match (e.g. `123.45.67.89`)
    - Wildcard (e.g. `192.168.*.*`)
    - CIDR blocks (e.g. `10.0.0.0/24`)
- ✅ Configurable storage (config or database)
- ✅ Middleware protection
- ✅ Blade directives
- ✅ Route macros
- ✅ Facade + helper function
- ✅ Artisan commands for managing IPs

---

📦 Installation
--------------

[](#-installation)

```
composer require xultech/laravel-ip-whitelist
```

Laravel will auto-discover the service provider and alias.

---

⚙️ Configuration
----------------

[](#️-configuration)

Publish the config file:

```
php artisan vendor:publish --provider="Xultech\LaravelIpWhitelist\IpWhitelistServiceProvider" --tag=ipwhitelist-config
```

Or create a custom `config/ipwhitelist.php`:

```
return [
    'enabled' => true,
    'storage' => 'config', // or 'database'

    'whitelisted_ips' => [
        '127.0.0.1',
        '192.168.*.*',
        '10.0.0.0/16',
    ],

    'table' => 'ip_whitelist_entries',
    'table_prefix' => '',

    'allow_env_override' => true,
    'env_key' => 'IP_WHITELIST_OVERRIDE',

    'response' => [
        'type' => 'abort', // redirect | json | abort
        'redirect_to' => '/unauthorized',
        'json' => [
            'message' => 'Your IP is not authorized.',
            'code' => 403,
        ],
        'status_code' => 403,
        'message' => 'Access denied. Your IP is not whitelisted.',
    ],
];
```

---

🛡️ Usage
--------

[](#️-usage)

### Middleware

[](#middleware)

Add globally in `Http\Kernel.php`:

```
'ipwhitelist' => \Xultech\LaravelIpWhitelist\Middleware\IpWhitelistMiddleware::class,
```

For Laravel 11+:

Add to your `bootstrap/app.php` file:

```
->withMiddleware(function (Middleware $middleware) {
    $middleware->alias([
        'ipwhitelist' => \Xultech\LaravelIpWhitelist\Middleware\IpWhitelistMiddleware::class,
    ]);
})
```

Apply to a route:

```
Route::middleware('ipwhitelist')->group(function () {
    Route::get('/admin', fn () => 'Protected');
});
```

### Route Macro

[](#route-macro)

```
Route::get('/admin', fn () => 'Protected')->ipWhitelisted();
```

### Blade Directive

[](#blade-directive)

```
@ipwhitelisted
    This content is visible only to whitelisted IPs.
@endipwhitelisted
```

### Facade

[](#facade)

```
use IpWhitelist;

if (IpWhitelist::isAllowed()) {
    // access granted
}
```

### Helper

[](#helper)

```
if (ip_whitelisted()) {
    // access granted
}
```

---

🧩 Using the Model
-----------------

[](#-using-the-model)

This package includes a built-in Eloquent model you can use to manage whitelisted IPs via database.

1. Run the migration: No need to publish anything. The package automatically loads its migration. ```
    php artisan migrate
    ```

    This creates the `ip_whitelist_entries` table (or your custom name, based on config).
2. Use the model in your code: ```
    use Xultech\LaravelIpWhitelist\Models\IpWhitelistEntry;

    IpWhitelistEntry::create([
        'ip' => '203.0.113.1',
        'active' => true,
    ]);

    // Query active entries
     $allowed = IpWhitelistEntry::where('active', true)->pluck('ip');
    ```

    You do not need to publish the model — it is fully usable directly from the package.

### 🛠 Customize the Table Name

[](#-customize-the-table-name)

In `config/ipwhitelist.php`, you can change:

```
'table' => 'ip_whitelist_entries',
'table_prefix' => '',
```

To create a custom table name like:

```
'table' => 'entries',
'table_prefix' => 'security_',
// Resolves to `security_entries`
```

---

⚡ Artisan Commands
------------------

[](#-artisan-commands)

CommandDescription`ipwhitelist:add {ip}`Add IP to the whitelist`ipwhitelist:remove {ip}`Remove IP from the whitelist`ipwhitelist:list`List whitelisted IPsOr, with example usage included directly under: **Examples:**

```
php artisan ipwhitelist:add 203.0.113.1 --store=database
php artisan ipwhitelist:remove 203.0.113.1 --store=database
php artisan ipwhitelist:list --store=database
```

---

🧪 Testing
---------

[](#-testing)

The package uses [Pest](https://pestphp.com) and [Orchestra Testbench](https://github.com/orchestral/testbench) for testing.

Run the test suite:

```
./vendor/bin/pest
```

✅ Requirements / Compatibility
------------------------------

[](#-requirements--compatibility)

- **PHP:** 7.3 – 8.4+
- **Laravel:** 6.x, 7.x, 8.x, 9.x, 10.x, 11.x, 12.x

> This package is tested across multiple Laravel versions and follows Laravel's release cycle. It works out of the box with both long-term support (LTS) and the latest Laravel versions.

📄 License
---------

[](#-license)

This package is open-sourced software licensed under the MIT license.

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome and appreciated!

To contribute:

1. Fork this repository
2. Create a new branch for your feature or fix: ```
    git checkout -b feature/my-feature
    ```
3. Make your changes with clear, descriptive commits
4. Write or update tests if applicable
5. Run the test suite to make sure everything passes: ```
    ./vendor/bin/pest
    ```
6. Push your branch:
7. Open a Pull Request and describe your changes

🧭 Guidelines
------------

[](#-guidelines)

- Follow **PSR-12** coding standards
- Keep pull requests **focused and minimal**
- For large changes, consider opening an issue first to discuss

Thank you for helping improve **Laravel IP Whitelist**!

👥 Credits &amp; Authors
-----------------------

[](#-credits--authors)

**Laravel IP Whitelist** was crafted with care by [Michael Erastus](https://github.com/michaelerastus) under [XulTech](https://github.com/Xultech-LTD) as part of our mission to build secure and developer-friendly Laravel tools.

### 🧑‍💻 Core Maintainer

[](#‍-core-maintainer)

- Michael Erastus — [GitHub](https://github.com/michaelerastus) · [Twitter/X](https://twitter.com/kopiumdev)

### 🤝 Contributors

[](#-contributors)

Special thanks to everyone who provided feedback, reported issues, or helped shape the direction of this package. Your support makes open source better.

If you find this package helpful, consider giving it a ⭐️ on GitHub or sharing it with others in the Laravel community.

For contributions, ideas, or collaborations, feel free to reach out!

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance46

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 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

410d ago

### Community

Maintainers

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

---

Top Contributors

[![michaelerastus](https://avatars.githubusercontent.com/u/33043109?v=4)](https://github.com/michaelerastus "michaelerastus (2 commits)")

---

Tags

authorizationip-whitelistip-whitelistinglaravellaravel-packagesecuritymiddlewarelaravelsecuritycidrip-whitelistip-filter

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/xultech-laravel-ip-whitelist/health.svg)

```
[![Health](https://phpackages.com/badges/xultech-laravel-ip-whitelist/health.svg)](https://phpackages.com/packages/xultech-laravel-ip-whitelist)
```

###  Alternatives

[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[cartalyst/sentinel

PHP 8.2+ Fully-featured Authentication &amp; Authorization System

1.6k2.7M72](/packages/cartalyst-sentinel)[orkhanahmadov/laravel-ip-middleware

Laravel middleware for whitelisting/blacklisting client IP addresses

2574.7k](/packages/orkhanahmadov-laravel-ip-middleware)[beatswitch/lock-laravel

A Laravel Driver for Lock.

15529.1k1](/packages/beatswitch-lock-laravel)[hosseinhezami/laravel-permission-manager

Advanced permission manager for Laravel.

403.3k](/packages/hosseinhezami-laravel-permission-manager)[rinvex/laravel-authy

Rinvex Authy is a simple wrapper for Authy TOTP, the best rated Two-Factor Authentication service for consumers, simplest 2fa Rest API for developers and a strong authentication platform for the enterprise.

3376.7k1](/packages/rinvex-laravel-authy)

PHPackages © 2026

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