This package requires PHP 8.1 and Laravel 10 or higher.
To install the PHP client library using Composer:
composer require coxlr/laravel-profanity
The package will automatically register the Profanity
provider and facade.
You can publish the config file with:
php artisan vendor:publish --provider="Coxlr\Profanity\ProfanityServiceProvider" --tag="config"
Then update config/profanity.php
with your credentials. Alternatively, you can update your .env
file with the following:
PROFANITY_REPLACEMENT_CHARACTER=*
PROFANITY_REPLACEMENT_LENGTH=4
PROFANITY_REPLACEMENT_LANGUAGES=en,es
To use Profanity you can use the facade, or request the instance from the service container.
$cleansedText = Profanity::clean('Using the facade to cleanse a string.');
/*
This function returns a string with any profanity found replaced with replace value set in the config.
*/
Or
$profanity = app('profanity');
$cleansedText = $profanity->clean('Using the instance to cleanse a string.');
$isClean = Profanity::isClean('The string to be checked.');
/*
This function returns a boolean value. If the string is clean, it will return true. If the string contains profanity, it will return false.
*/
$cleansedText = Profanity::setLanguages('en,es,fr')->clean('The string to be cleansed.');
Strict mode will replace any profanity found even if it is found within a word, and not just the exact word.
$cleansedText = Profanity::setStrict(true)->clean('The string to be cleansed.');
$isClean = Profanity::setStrict(true)->isClean('The string to be checked.');
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email hey@leecox.me instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.