Skip to content

🤬🤭 Laravel validation rule that checks if a string is offensive.

License

Notifications You must be signed in to change notification settings

DivineOmega/laravel-offensive-validation-rule

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤬🤭 Laravel Offensive Validation Rule

This package provides a Laravel validation rule that checks if a string is offensive. It can be useful to check user supplied data that may be publicly displayed, such as usernames or comments.

Laravel Offensive Validation Rule usage

Coverage Status StyleCI

Installation

To install, just run the following Composer command.

composer require divineomega/laravel-offensive-validation-rule

Please note that this package requires Laravel 5.5 or above.

Usage

The following code snippet shows an example of how to use the offensive validation rule.

use DivineOmega\LaravelOffensiveValidationRule\Offensive;

$request->validate([
    'username' => ['required', new Offensive],
]);

Custom word lists

If the defaults are too strict (or not strict enough), you can optionally specify a custom list of offensive words and custom whitelist. Below is an example of using a custom blacklist and whitelist.

use DivineOmega\LaravelOffensiveValidationRule\Offensive;
use DivineOmega\IsOffensive\OffensiveChecker;

$blacklist = ['moist', 'stinky', 'poo'];
$whitelist = ['poop'];

$request->validate([
    'username' => ['required', new Offensive(new OffensiveChecker($blacklist, $whitelist))],
]);