kamranahmedse/laravel-censor
| Install | |
|---|---|
composer require kamranahmedse/laravel-censor |
|
| Latest Version: | v2.0 |
| PHP: | >=5.4.0 |
| License: | MIT |
| Last Updated: | Mar 1, 2016 |
| Links: | GitHub · Packagist |
Laravel Censor
Let's you easily redact or replace the occurences of
words,sentencesor%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
Perform the following operations in order to use this middleware
-
Run
composer require kamranahmedse/laravel-censorin your terminal -
Add Service Provider Open
config/app.phpand addKamranAhmed\LaravelCensor\LaravelCensorServiceProvider::classto the end ofprovidersarray:'providers' => array( .... KamranAhmed\LaravelCensor\LaravelCensorServiceProvider::class, ), -
Register the Middleware After that open the file
app/Http/Kernel.phpand add the following'censor' => \KamranAhmed\LaravelCensor\CensorMiddleware::classto the end of
$routeMiddlewarearrayprotected $routeMiddleware = [ ... 'censor' => \KamranAhmed\LaravelCensor\CensorMiddleware::class ]; -
Publish Configuration Open terminal and run
php artisan vendor:publish
How to use
-
After following the above steps, there will be a
censor.phpfile inside theconfigdirectory. The file has two arrays, namelyreplaceandredact. -
You have to specify the words that you want to replace in the
replacearray 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
redactor completely remove, you have to specify them in theredactarray'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
redactarray will turn into asterisks. For exampleidiotwill be turned into 5 asterisks (*****). -
Now for any route from which you want these words to be redacted or replaced, place the middleware
censorover 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
- 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
- Also you can reach me directly at kamranahmed.se@gmail.com with any feedback
Related Packages
Laravel Route Usage Tracker Package with Vue.js 3 Dashboard and Inertia.js Suppo...
A Laravel package to help you in implementing the transformers logic in your app...
Provides support for enforcing Content Security Policy with headers in Laravel r...
Configurable localization middleware for your Laravel >=5.1 application
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v2.0 | >=5.4.0 | ^5.1.11 | MIT | |
| 1.0.1 | >=5.4.0 | ^5.1.11 | MIT | |
| 1.0 | >=5.4.0 | ^5.1.11 | MIT |