PHPackages                             neelkanthk/laravel-surveillance - 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. neelkanthk/laravel-surveillance

ActiveLaravel-package[Security](/categories/security)

neelkanthk/laravel-surveillance
===============================

Put users, IP addresses and anonymous browser fingerprints on surveillance and block malicious ones.

1.3.0(5y ago)22790317[4 PRs](https://github.com/neelkanthk/laravel-surveillance/pulls)1MITPHPPHP &gt;=7.2

Since Sep 29Pushed 4y ago8 watchersCompare

[ Source](https://github.com/neelkanthk/laravel-surveillance)[ Packagist](https://packagist.org/packages/neelkanthk/laravel-surveillance)[ RSS](/packages/neelkanthk-laravel-surveillance/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (13)Used By (1)

[![Laravel Surveillance Logo](https://github.com/neelkanthk/repo_logos/raw/master/LaravelSurveillance_small.png?raw=true)](https://github.com/neelkanthk/repo_logos/blob/master/LaravelSurveillance_small.png?raw=true)

[![](https://camo.githubusercontent.com/45cc9d9cf0dd4d4c55967dd0ad4077916a51a0ae32f60ef43466b13a7bc20358/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6e65656c6b616e74686b2f6c61726176656c2d7375727665696c6c616e63653f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/45cc9d9cf0dd4d4c55967dd0ad4077916a51a0ae32f60ef43466b13a7bc20358/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6e65656c6b616e74686b2f6c61726176656c2d7375727665696c6c616e63653f7374796c653d666f722d7468652d6261646765)[![](https://camo.githubusercontent.com/c9ba975dcd86e902611fce58781add738b80d80643a8cfcf7cef1bb76e6d6ca4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6e65656c6b616e74686b2f6c61726176656c2d7375727665696c6c616e63652e7376673f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/c9ba975dcd86e902611fce58781add738b80d80643a8cfcf7cef1bb76e6d6ca4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6e65656c6b616e74686b2f6c61726176656c2d7375727665696c6c616e63652e7376673f7374796c653d666f722d7468652d6261646765)[![](https://camo.githubusercontent.com/3d574f9beaff1dff3f8892b94b1138e994ce0f5c0b5ef65108e1ee92e27775a7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d253345253344362e302d7265643f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/3d574f9beaff1dff3f8892b94b1138e994ce0f5c0b5ef65108e1ee92e27775a7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d253345253344362e302d7265643f7374796c653d666f722d7468652d6261646765)[![](https://camo.githubusercontent.com/43effafbeb921f0da5a382b809f802cda31eff80df4315bd9d0929fae2ae5320/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6e65656c6b616e74686b2f6c61726176656c2d7375727665696c6c616e63653f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/43effafbeb921f0da5a382b809f802cda31eff80df4315bd9d0929fae2ae5320/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6e65656c6b616e74686b2f6c61726176656c2d7375727665696c6c616e63653f7374796c653d666f722d7468652d6261646765)[![](https://camo.githubusercontent.com/c9561fb45f87883fb93cb101fa108df4c72daa655bddb8734d3cbcd625ab133a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6e65656c6b616e74686b2f6c61726176656c2d7375727665696c6c616e63653f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/c9561fb45f87883fb93cb101fa108df4c72daa655bddb8734d3cbcd625ab133a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6e65656c6b616e74686b2f6c61726176656c2d7375727665696c6c616e63653f7374796c653d666f722d7468652d6261646765)[![](https://camo.githubusercontent.com/0b6faa4bc619fef0ccc35c52bb474dc85c4a543b63ea7b816e65800bb7b7356a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6e65656c6b616e74686b2f6c61726176656c2d7375727665696c6c616e63653f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/0b6faa4bc619fef0ccc35c52bb474dc85c4a543b63ea7b816e65800bb7b7356a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6e65656c6b616e74686b2f6c61726176656c2d7375727665696c6c616e63653f7374796c653d666f722d7468652d6261646765)

Laravel Surveillance [![Twitter](https://camo.githubusercontent.com/2314026249fe5ef2768852c682f2b6a52b2aeb17ee64de5d5dc50c4c66788986/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f75726c3f7374796c653d736f6369616c2675726c3d68747470732533412532462532466769746875622e636f6d2532466e65656c6b616e74686b2532466c61726176656c2d7375727665696c6c616e6365)](https://twitter.com/intent/tweet?text=Laravel%20Surveillance:&url=https%3A%2F%2Fgithub.com%2Fneelkanthk%2Flaravel-surveillance)
=======================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#laravel-surveillance-)

Laravel Surveillance is a package to put malicious users, IP addresses and anonymous browser fingerprints under surveillance, write surveillance logs and block malicious ones from accessing the app.

---

> **Please read the IMPORTANT INFORMATION below before using this package**

> **This package collects and processes various attributes that may be Personal Identifiable Information and this should therefore be disclosed and screened before adopting this package. This packages author does not take responsibility for any compliance issues users may face. Please consult legal expertise to use responsibly.**

---

---

**This package provides**:

*1. A middleware to be used on routes.*

*2. A command line interface to enable/disable surveillance and block/unblock access.*

*3. A fluent API to programmatically enable/disable surveillance, block/unblock access and log the requests at runtime.*

*4. By default the package used MySQL database as storage but the package can be extended to use virtually any storage technology.*

**NOTE: This package does not provide a client side library for browser fingerprinting. [FingerprintJS Open Source](https://github.com/fingerprintjs/fingerprintjs) is a good library to use for client side browser fingerprinting.**

### Important Announcement !

[](#important-announcement-)

Introducing [Laravel Surveillance UI](https://github.com/neelkanthk/laravel-surveillance-ui) : A package which provides Graphical UI for Laravel Surveillance and integrates within your existing application.

### Minimum Requirements

[](#minimum-requirements)

#### 1. Laravel 6.0

[](#1-laravel-60)

#### 2. PHP 7.2

[](#2-php-72)

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

[](#installation)

#### 1. Install the package via composer:

[](#1-install-the-package-via-composer)

```
composer require neelkanthk/laravel-surveillance
```

#### 2.1. Publish the migration files:

[](#21-publish-the-migration-files)

```
php artisan vendor:publish --provider="Neelkanth\Laravel\Surveillance\Providers\SurveillanceServiceProvider" --tag="migrations"
```

#### 2.2. Publish language files:

[](#22-publish-language-files)

```
php artisan vendor:publish --provider="Neelkanth\Laravel\Surveillance\Providers\SurveillanceServiceProvider" --tag="lang"
```

#### 3. Run the migrations

[](#3-run-the-migrations)

```
php artisan migrate
```

#### 4. After migrations have been run two tables will be created in the database namely `surveillance_managers` and `surveillance_logs`

[](#4-after-migrations-have-been-run-two-tables-will-be-created-in-the-database-namely-surveillance_managers-and-surveillance_logs)

#### 5. You can publish the config file with:

[](#5-you-can-publish-the-config-file-with)

```
php artisan vendor:publish --provider="Neelkanth\Laravel\Surveillance\Providers\SurveillanceServiceProvider" --tag="config"
```

This is the contents of the file that will be published at `config/surveillance.php`:

```
return [

    /*
     * The name of the header to be used for browser fingerprint
     */
    "fingerprint-header-key" => "fingerprint",

    /*
     *  This class is responsible enabling, disabling, blocking and unblocking.
     *  To override the default functionality extend the below class and provide its name here.
     */
    "manager-repository" => 'Neelkanth\Laravel\Surveillance\Implementations\SurveillanceManagerRepository',

    /*
     *  This class is responsible for logging the surveillance enabled requests
     *  To override the default functionality extend the below class and provide its name here.
     */
    "log-repository" => 'Neelkanth\Laravel\Surveillance\Implementations\SurveillanceLogRepository',

    /*
     *  The types which are allowed currently.
     *  DO NOT MODIFY THESE
     */
    "allowed-types" => ["userid", "ip", "fingerprint"]
];
```

CLI Usage
---------

[](#cli-usage)

#### Enable surveillance for an IP Address

[](#enable-surveillance-for-an-ip-address)

```
php artisan surveillance:enable ip 192.1.2.4
```

#### Disable surveillance for an IP Address

[](#disable-surveillance-for-an-ip-address)

```
php artisan surveillance:disable ip 192.1.2.4
```

#### Enable surveillance for a User ID

[](#enable-surveillance-for-a-user-id)

```
php artisan surveillance:enable userid 1234
```

#### Disable surveillance for a User ID

[](#disable-surveillance-for-a-user-id)

```
php artisan surveillance:disable userid 1234
```

#### Enable surveillance for Browser Fingerprint

[](#enable-surveillance-for-browser-fingerprint)

```
php artisan surveillance:enable fingerprint hjP0tLyIUy7SXaSY6gyb
```

#### Disable surveillance for Browser Fingerprint

[](#disable-surveillance-for-browser-fingerprint)

```
php artisan surveillance:disable fingerprint hjP0tLyIUy7SXaSY6gyb
```

#### Block an IP Address

[](#block-an-ip-address)

```
php artisan surveillance:block ip 192.1.2.4
```

#### UnBlock an IP Address

[](#unblock-an-ip-address)

```
php artisan surveillance:unblock ip 192.1.2.4
```

#### Block a User ID

[](#block-a-user-id)

```
php artisan surveillance:block userid 1234
```

#### UnBlock a User ID

[](#unblock-a-user-id)

```
php artisan surveillance:unblock userid 1234
```

#### Block a Browser Fingerprint

[](#block-a-browser-fingerprint)

```
php artisan surveillance:block fingerprint hjP0tLyIUy7SXaSY6gyb
```

#### UnBlock a Browser Fingerprint

[](#unblock-a-browser-fingerprint)

```
php artisan surveillance:unblock fingerprint hjP0tLyIUy7SXaSY6gyb
```

#### Remove a Surveillance record from Database

[](#remove-a-surveillance-record-from-database)

```
php artisan surveillance:remove ip 192.5.4.3
```

Middleware Usage
----------------

[](#middleware-usage)

#### You can use the 'surveillance' middleware on any route or route group just like any other middleware.

[](#you-can-use-the-surveillance-middleware-on-any-route-or-route-group-just-like-any-other-middleware)

### *NOTE: The middleware looks for the browser fingerprint in the header name as set in the `fingerprint-header-key` inside `config/surveillance.php`*

[](#note-the-middleware-looks-for-the-browser-fingerprint-in-the-header-name-as-set-in-the-fingerprint-header-key-inside-configsurveillancephp)

```
Route::middleware(["surveillance"])->get('/', function () {

});
```

Programmatic Usage
------------------

[](#programmatic-usage)

#### Enable Surveillance

[](#enable-surveillance)

```
use Neelkanth\Laravel\Surveillance\Services\Surveillance;
Surveillance::manager()->type("ip")->value("192.5.4.1")->enableSurveillance();
```

#### Block Access

[](#block-access)

```
use Neelkanth\Laravel\Surveillance\Services\Surveillance;
Surveillance::manager()->type("userid")->value(2121)->blockAccess();
```

#### Logging a Request (Works when surveillance in enabled on User ID, IP Address or Browser Fingerprint)

[](#logging-a-request-works-when-surveillance-in-enabled-on-user-id-ip-address-or-browser-fingerprint)

```
use Neelkanth\Laravel\Surveillance\Services\Surveillance;
Surveillance::logger()->writeLog();
```

Allowed Types
-------------

[](#allowed-types)

#### Currently only userid, ip and fingerprint types are allowed.

[](#currently-only-userid-ip-and-fingerprint-types-are-allowed)

Customizing and Overriding the defaults
---------------------------------------

[](#customizing-and-overriding-the-defaults)

### To override the default surveillance management functionality

[](#to-override-the-default-surveillance-management-functionality)

#### Step 1: Extend the `SurveillanceManagerRepository` Class and override all of its methods

[](#step-1-extend-the-surveillancemanagerrepository-class-and-override-all-of-its-methods)

```
//Example repository to use MongoDB instead of MySQL
namespace App;

use Neelkanth\Laravel\Surveillance\Implementations\SurveillanceManagerRepository;
use Illuminate\Support\Carbon;

class SurveillanceManagerMongoDbRepository extends SurveillanceManagerRepository
{
    public function enableSurveillance()
    {
        $surveillance = $this->getRecord();
        if (is_null($surveillance)) {
            $surveillance["type"] = $this->getType();
            $surveillance["value"] = $this->getValue();
        }
        $surveillance["surveillance_enabled"] = 1;
        $surveillance["surveillance_enabled_at"] = Carbon::now()->toDateTimeString();
        $collection = (new \MongoDB\Client)->surveillance->manager;
        $insertOneResult = $collection->insertOne($surveillance);
        return $insertOneResult;
    }
}
```

#### Step 2: Provide the custom class in the `config/surveillance.php` file's `manager-repository` key

[](#step-2-provide-the-custom-class-in-the-configsurveillancephp-files-manager-repository-key)

```
/*
 *  This class is responsible enabling, disabling, blocking and unblocking.
 *  To override the default functionality extend the below class and provide its name here.
 */
"manager-repository" => 'App\SurveillanceManagerMongoDbRepository',
```

### To override the default logging funtionality

[](#to-override-the-default-logging-funtionality)

#### Step 1: Extend the `SurveillanceLogRepository` Class and override all of its methods

[](#step-1-extend-the-surveillancelogrepository-class-and-override-all-of-its-methods)

```
//Example repository to write Logs in MongoDB instead of MySQL
namespace App;

use Neelkanth\Laravel\Surveillance\Implementations\SurveillanceLogRepository;

class SurveillanceLogMongoDbRepository extends SurveillanceLogRepository
{
    public function writeLog($dataToLog = null)
    {
        if (!is_null($dataToLog)) {
            $this->setLogToWrite($dataToLog);
        }
        $log = $this->getLogToWrite();
        if (!empty($log) && is_array($log)) {
            $collection = (new \MongoDB\Client)->surveillance->logs;
            $insertOneResult = $collection->insertOne($log);
        }
    }
}
```

#### Step 2: Provide the custom class in the `config/surveillance.php` file's `log-repository` key

[](#step-2-provide-the-custom-class-in-the-configsurveillancephp-files-log-repository-key)

```
/*
 *  This class is responsible for logging the surveillance enabled requests
 *  To override the default functionality extend the below class and provide its name here.
*/
"log-repository" => 'App\SurveillanceLogMongoDbRepository',
```

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

[](#contributing)

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Security
--------

[](#security)

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

Credits
-------

[](#credits)

- [Neelkanth Kaushik](https://github.com/neelkanthk)
- [All Contributors](../../contributors)
- [CCTV Icon](https://pixabay.com/vectors/image-sign-warning-icon-cctv-3042333)

License
-------

[](#license)

[MIT](https://choosealicense.com/licenses/mit/)

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity56

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

Total

10

Last Release

2035d ago

PHP version history (2 changes)1.0.0PHP ^7.2

v1.2.0.x-devPHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/8d024795d1517d97c691382c2ff955cb3157ccab11222cbcb3b91d00bc2fe8c1?d=identicon)[Neelkanth Kaushik](/maintainers/Neelkanth%20Kaushik)

---

Top Contributors

[![neelkanthk](https://avatars.githubusercontent.com/u/16952465?v=4)](https://github.com/neelkanthk "neelkanthk (31 commits)")

---

Tags

access-controlapplication-securitycybersecurityfingerprintjsfingerprintjs2hacktoberfesthacktoberfest2024laravellaravel-packagelaravel-securitylaravel-surveillancephpphplaravellaravel-packageLaravel Securityaccess-controlfingerprintjsfingeprintjs2

### Embed Badge

![Health badge](/badges/neelkanthk-laravel-surveillance/health.svg)

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

###  Alternatives

[imanghafoori/laravel-password-history

A package to keep a history of all password changes of users

70190.9k1](/packages/imanghafoori-laravel-password-history)[tzsk/otp

A secure, database-free One-Time Password (OTP) generator and verifier for PHP and Laravel.

241641.4k1](/packages/tzsk-otp)[salehhashemi/laravel-repository

Implementing the repository pattern for Laravel projects.

2010.5k](/packages/salehhashemi-laravel-repository)

PHPackages © 2026

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