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

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

orkhanahmadov/laravel-ip-middleware
===================================

Laravel middleware for whitelisting/blacklisting client IP addresses

1.10.0(11mo ago)2580.3k↓52.4%10[1 issues](https://github.com/orkhanahmadov/laravel-ip-middleware/issues)[1 PRs](https://github.com/orkhanahmadov/laravel-ip-middleware/pulls)MITPHPPHP ^8.0CI failing

Since Sep 18Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/orkhanahmadov/laravel-ip-middleware)[ Packagist](https://packagist.org/packages/orkhanahmadov/laravel-ip-middleware)[ Docs](https://github.com/orkhanahmadov/laravel-ip-middleware)[ RSS](/packages/orkhanahmadov-laravel-ip-middleware/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (6)Dependencies (5)Versions (12)Used By (0)

Laravel IP middleware
=====================

[](#laravel-ip-middleware)

[![Latest Stable Version](https://camo.githubusercontent.com/a55e1b47beff321216d2c4172408ba4f99618ab148c8418e4792e8f03f861f89/68747470733a2f2f706f7365722e707567782e6f72672f6f726b68616e61686d61646f762f6c61726176656c2d69702d6d6964646c65776172652f762f737461626c65)](https://packagist.org/packages/orkhanahmadov/laravel-ip-middleware)[![Latest Unstable Version](https://camo.githubusercontent.com/76aa69dd7952cf8ba2c47bf595f2c425d932cb1e74579c233ac3599683d15401/68747470733a2f2f706f7365722e707567782e6f72672f6f726b68616e61686d61646f762f6c61726176656c2d69702d6d6964646c65776172652f762f756e737461626c65)](https://packagist.org/packages/orkhanahmadov/laravel-ip-middleware)[![Total Downloads](https://camo.githubusercontent.com/fce033e882e7e6a4a76a72cdbb3a5ee904c8c90d0c0b250d362f79044fd87c1e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f726b68616e61686d61646f762f6c61726176656c2d69702d6d6964646c6577617265)](https://packagist.org/packages/orkhanahmadov/laravel-ip-middleware)[![License](https://camo.githubusercontent.com/15bd2ff61831f1f8dd07a1695f2a88705501b7f019c2f9e084f054904fe04fa4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6f726b68616e61686d61646f762f6c61726176656c2d69702d6d6964646c65776172652e737667)](https://github.com/orkhanahmadov/laravel-ip-middleware/blob/master/LICENSE.md)

[![Build Status](https://camo.githubusercontent.com/2d1415106549b54c3a3ed44cf5a58bfc6d250dbe719ec118606b671303c777cb/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6f726b68616e61686d61646f762f6c61726176656c2d69702d6d6964646c65776172652e737667)](https://travis-ci.org/orkhanahmadov/laravel-ip-middleware)[![Test Coverage](https://camo.githubusercontent.com/3f27369e8aa4824fb4035961e109bb665c4ceb0d2ae5198342e423de7fd35b4d/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f35376637353232643937383837383265333234362f746573745f636f766572616765)](https://codeclimate.com/github/orkhanahmadov/laravel-ip-middleware/test_coverage)[![Maintainability](https://camo.githubusercontent.com/517d2afbc01ead270567452b1441df85bf921704fc3617b75223bfb7c2ba4623/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f35376637353232643937383837383265333234362f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/orkhanahmadov/laravel-ip-middleware/maintainability)[![Quality Score](https://camo.githubusercontent.com/dfc1455ffaf616882b9d6a1d037d7499130fc01bea2a55c59970a874f9d518ec/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6f726b68616e61686d61646f762f6c61726176656c2d69702d6d6964646c65776172652e737667)](https://scrutinizer-ci.com/g/orkhanahmadov/laravel-ip-middleware)[![StyleCI](https://camo.githubusercontent.com/fd4f1337b8f9155fff4f1322bf4ba227b8b6d258b92cebff57728c062b4f3c63/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3230393335373633352f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/209357635)

Laravel middleware for whitelisting/blacklisting client IP addresses

Requirements
------------

[](#requirements)

- PHP **8.0** or higher
- Laravel **8** or higher

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

[](#installation)

You can install the package via composer:

```
composer require orkhanahmadov/laravel-ip-middleware
```

Usage
-----

[](#usage)

Packages comes with `WhitelistMiddleware` and `BlacklistMiddleware` middlewares. You can register any or both of them in `$routeMiddleware` in `app/Http/Kernel.php` file:

```
protected $routeMiddleware = [
    // ...
    'ip_whitelist' => \Orkhanahmadov\LaravelIpMiddleware\WhitelistMiddleware::class,
    'ip_blacklist' => \Orkhanahmadov\LaravelIpMiddleware\BlacklistMiddleware::class,
];
```

Use middlewares in any of your routes and pass IP addresses.

```
Route::middleware('ip_whitelist:1.1.1.1')->get('/', 'HomeController@index');
Route::middleware('ip_blacklist:3.3.3.3')->get('/', 'PostController@index');
```

- `ip_whitelist` middleware will block any requests where client IP not matching with whitelisted IPs.
- `ip_blacklist` middleware will block requests coming from blacklisted IPs.

You can also pass multiple IP addresses separated with comma:

```
Route::middleware('ip_whitelist:1.1.1.1,2.2.2.2')->get('/', 'HomeController@index');
```

This will block all requests where client IP not matching whitelisted IP list.

Package also allows setting predefine IP list in config and use them with name:

```
// config/ip-middleware.php

'predefined_lists' = [
    'my-list-1' => ['1.1.1.1', '2.2.2.2'],
    'my-list-2' => ['3.3.3.3', '4.4.4.4'],
];
```

```
Route::middleware('ip_whitelist:my-list-1,my-list-2')->get('/', 'HomeController@index');
// you can also mix predefined list with additional IP addresses
Route::middleware('ip_whitelist:my-list-1,my-list-2,5.5.5.5,6.6.6.6')->get('/', 'PostController@index');
```

Configuration
-------------

[](#configuration)

Run this command to publish package config file:

```
php artisan vendor:publish --provider="Orkhanahmadov\LaravelIpMiddleware\LaravelIpMiddlewareServiceProvider"
```

`ip-middleware.php` config file contains following settings:

- `ignore_environments` - Middleware ignores IP checking when application is running in listed environments.
- `error_code` - HTTP code that shown when request gets rejected.
- `custom_server_parameter` - Custom $\_SERVER parameter to look for IP address
- `predefined_lists` - Predefined IP lists

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

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

[](#contributing)

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

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Orkhan Ahmadov](https://github.com/orkhanahmadov)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance51

Moderate activity, may be stable

Popularity42

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 92.7% 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 ~214 days

Recently: every ~331 days

Total

11

Last Release

332d ago

PHP version history (4 changes)1.0.0PHP ^7.1

1.3.0PHP ^7.2

1.6.0PHP ^7.2|^8.0

1.8.0PHP ^8.0

### Community

Maintainers

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

---

Top Contributors

[![orkhanahmadov](https://avatars.githubusercontent.com/u/7041590?v=4)](https://github.com/orkhanahmadov "orkhanahmadov (51 commits)")[![chrisreedio](https://avatars.githubusercontent.com/u/77644584?v=4)](https://github.com/chrisreedio "chrisreedio (1 commits)")[![kosmonowt](https://avatars.githubusercontent.com/u/1159594?v=4)](https://github.com/kosmonowt "kosmonowt (1 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (1 commits)")[![sc-creed](https://avatars.githubusercontent.com/u/89997008?v=4)](https://github.com/sc-creed "sc-creed (1 commits)")

---

Tags

ip-filterip-whitelistlaravelmiddlewaremiddlewarelaravelip-whitelistip-filterip-blacklistorkhanahmadovlaravel-ip-middleware

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M345](/packages/psalm-plugin-laravel)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77022.3M151](/packages/laravel-mcp)[illuminate/auth

The Illuminate Auth package.

10528.2M1.2k](/packages/illuminate-auth)[api-platform/laravel

API Platform support for Laravel

58171.5k14](/packages/api-platform-laravel)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.6k3](/packages/defstudio-telegraph)[illuminate/routing

The Illuminate Routing package.

1419.2M3.0k](/packages/illuminate-routing)

PHPackages © 2026

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