PHPackages                             effilib/laravel-restrict-ip-middleware - 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. effilib/laravel-restrict-ip-middleware

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

effilib/laravel-restrict-ip-middleware
======================================

A Laravel package to restrict access by IP addresses, CIDR ranges, route names, or URI patterns.

1.0.2(9mo ago)011MITPHPPHP ^8.1CI passing

Since Sep 12Pushed 9mo agoCompare

[ Source](https://github.com/effilib/laravel-restrict-ip-middleware)[ Packagist](https://packagist.org/packages/effilib/laravel-restrict-ip-middleware)[ RSS](/packages/effilib-laravel-restrict-ip-middleware/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

Laravel Restrict IP Middleware
==============================

[](#laravel-restrict-ip-middleware)

A Laravel middleware package to **restrict access** based on:

- Exact IP addresses
- CIDR ranges
- Route names (supports wildcards)
- URI patterns

This allows you to secure sensitive areas of your application, while still defining **exception rules** (whitelisted routes or URIs that always stay accessible).

---

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

[](#-installation)

Install via Composer:

```
composer require effilib/laravel-restrict-ip-middleware
```

Laravel will auto-discover the service provider.

---

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

[](#️-publish-configuration)

Publish the configuration file:

```
php artisan vendor:publish --provider="Effilib\RestrictIp\Providers\RestrictIpServiceProvider" --tag=config
```

This will create:

```
config/effilib-restrict-ip.php

```

---

🔑 Usage
-------

[](#-usage)

Apply the middleware to routes or groups.

### Default ruleset

[](#default-ruleset)

```
use Effilib\RestrictIp\Middleware\RestrictIpMiddleware;

Route::get('/admin', fn () => 'Admin Area')
    ->middleware(RestrictIpMiddleware::class);
```

### Custom ruleset

[](#custom-ruleset)

```
Route::get('/custom', fn () => 'Special Area')
    ->middleware(RestrictIpMiddleware::class . ':custom');
```

The middleware parameter (`:custom`) selects which **ruleset** from `effilib-restrict-ip.php` to apply.

---

🛠 Configuration
---------------

[](#-configuration)

Example `config/effilib-restrict-ip.php`:

```
return [

    // HTTP status code when access is denied
    'error_code' => 403,

    'rules' => [

        // Default ruleset
        'default' => [

            // Allowed exact IPs
            'allowed_ips' => [
                '127.0.0.1',
                '::1',
            ],

            // Allowed CIDR ranges
            'allowed_cidrs' => [
                // '192.168.0.0/24',
            ],

            // Exception: always allow these route names (supports wildcards)
            'allowed_routes' => [
                // 'healthcheck',
                // 'api.*',
            ],

            // Exception: always allow these URI patterns
            'allowed_uri_patterns' => [
                // 'status*',
                // 'public/*',
            ],
        ],

        // Example custom ruleset
        'custom' => [
            'allowed_ips' => ['10.0.0.1'],
            'allowed_uri_patterns' => ['public-reports/*'],
        ],
    ],
];
```

---

🔒 How it works
--------------

[](#-how-it-works)

The middleware checks in this order:

1. **Allowed route names** → if matched, always allowed
2. **Allowed URI patterns** → if matched, always allowed
3. **Exact IP addresses** → if matched, allowed
4. **CIDR ranges** → if matched, allowed
5. **Otherwise denied** → returns configured error code (default: `403`)

---

🧪 Example
---------

[](#-example)

```
// routes/web.php

use Effilib\RestrictIp\Middleware\RestrictIpMiddleware;

Route::middleware([RestrictIpMiddleware::class])->group(function () {
    Route::get('/admin', fn () => 'Admin dashboard');
    Route::get('/settings', fn () => 'System settings');
});

// Healthcheck route always accessible
Route::get('/healthcheck', fn () => 'OK')
    ->name('healthcheck');
```

With this setup:

- `/admin` and `/settings` require a matching IP or CIDR

---

📜 License
---------

[](#-license)

MIT License © Effilib

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance56

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

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

294d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/231692792?v=4)[effilib](/maintainers/effilib)[@effilib](https://github.com/effilib)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/effilib-laravel-restrict-ip-middleware/health.svg)

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

###  Alternatives

[directorytree/ldaprecord-laravel

LDAP Authentication &amp; Management for Laravel.

5752.3M18](/packages/directorytree-ldaprecord-laravel)[illuminate/auth

The Illuminate Auth package.

10528.2M1.2k](/packages/illuminate-auth)[althinect/filament-spatie-roles-permissions

3481.1M10](/packages/althinect-filament-spatie-roles-permissions)[masterix21/laravel-licensing

Laravel licensing package with polymorphic assignment to any model, activation keys, expirations/renewals, and seat control via LicenseUsage. Supports offline verification with public-key–signed tokens, a CLI to generate/rotate/revoke keys, and an extensible architecture via config and contracts.

1563.0k4](/packages/masterix21-laravel-licensing)

PHPackages © 2026

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