PHPackages                             kamranahmedse/laravel-censor - 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. kamranahmedse/laravel-censor

ActiveLibrary

kamranahmedse/laravel-censor
============================

A middleware to censor certain words from your pages

v2.0(10y ago)438527MITPHPPHP &gt;=5.4.0

Since Nov 13Pushed 10y ago4 watchersCompare

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

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

Laravel Censor
==============

[](#laravel-censor)

> Let's you easily redact or replace the occurences of `words`, `sentences` or `%wildcards%`

A laravel middleware that will automatically censor the words that you will specify. All you have to do is specify the things, that you want to redact or replace, in a configuration file and these words will automatically be redacted/replaced from the views on whose route you will specify the middleware.

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

[](#installation)

Perform the following operations in order to use this middleware

- Run `composer require kamranahmedse/laravel-censor` in your terminal
- **Add Service Provider**Open `config/app.php` and add `KamranAhmed\LaravelCensor\LaravelCensorServiceProvider::class` to the end of `providers` array:

    ```
    'providers' => array(
        ....
        KamranAhmed\LaravelCensor\LaravelCensorServiceProvider::class,
    ),

    ```
- **Register the Middleware** After that open the file `app/Http/Kernel.php` and add the following

    ```
    'censor' => \KamranAhmed\LaravelCensor\CensorMiddleware::class

    ```

    to the end of `$routeMiddleware` array

    ```
     protected $routeMiddleware = [
         ...
         'censor' => \KamranAhmed\LaravelCensor\CensorMiddleware::class
     ];

    ```
- **Publish Configuration** Open terminal and run

    ```
    php artisan vendor:publish
    ```

How to use
----------

[](#how-to-use)

- After following the above steps, there will be a `censor.php` file inside the `config` directory. The file has two arrays, namely `replace` and `redact`.
- You have to specify the words that you want to replace in the `replace` array with words or wildcards set to the keys of array and replacements as values i.e.

    ```
    'replace' => [
        'idiot'    => '(not a nice word)',
        'hate%'    => 'peace',      // Wildcard: Will replace the words beginning at hate e.g. hatered, hate, hated etc
        '%eograph%' =>  'some-graphy-word',         // Willcard: Will replace words containing `eograph` anywhere in the middle e.g. geographic, angeography etc
        'seventh'  => '7th',
        'monthly'  => 'every month',
        'yearly'   => 'every year',
        'weekly'   => 'every week',
    ],
    ```
- For any words that you want to `redact` or completely remove, you have to specify them in the `redact` array

    ```
    'redact' => [
       'idiot%',        // e.g. idiot will be replaced with 5 asterisks, idiotic with 7 asterisks etc
       'password',      // Will be replaced with 8 asterisks
       'word-that-i-really-dislike',
    ],
    ```

    The words specified in `redact` array will turn into asterisks. For example `idiot` will be turned into 5 asterisks (\*\*\*\*\*).
- Now for any route from which you want these words to be redacted or replaced, place the middleware `censor` over it and it will automatically redact/replace those words from all of the page. For example, below is how you can specify it over the route e.g.

    ```
    Route::get('post-detail', ['middleware' => 'censor', 'uses' => 'PostController@detail', 'as' => 'postDetail']);
    ```

    Or specify it over the route group so that it may handle all the routes in that group e.g.

    ```
    Route::group(['prefix' => 'post', 'middleware' => 'censor'], function () {
        Route::get('detail', ['uses' => 'PostController@detail']);
        Route::get('add', ['uses' => 'PostController@add']);
    });
    ```

How to Contribute
-----------------

[](#how-to-contribute)

- Feel free to add some new functionality, improve some existing functionality etc and open up a pull request explaining what you did.
- Report any issues in the [issues section](https://github.com/kamranahmedse/laravel-censor/issues)
- Also you can reach me directly at  with any feedback

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Total

3

Last Release

3724d ago

Major Versions

1.0.1 → v2.02016-03-01

### Community

Maintainers

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

---

Top Contributors

[![kamranahmedse](https://avatars.githubusercontent.com/u/4921183?v=4)](https://github.com/kamranahmedse "kamranahmedse (13 commits)")

---

Tags

middlewarelaravelroutecensorredactkamranahmedselaravel-censorcensor-pages

### Embed Badge

![Health badge](/badges/kamranahmedse-laravel-censor/health.svg)

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

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[spatie/laravel-authorize

A middleware to check authorization

20125.8k1](/packages/spatie-laravel-authorize)[masterro/laravel-xss-filter

Filter user input for XSS but don't touch other html

41254.5k](/packages/masterro-laravel-xss-filter)

PHPackages © 2026

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