Blasp is a Laravel profanity filter bundle that helps detect and masks profane phrases. It offers profanity detection, substitution choices, obfuscation, and extra.
use BlaspsoftBlaspFacadesBlasp;
$sentence = 'Laravel Information kicks ass!';
$blasp = Blasp::examine($sentence);
$blasp->getSourceString(); // "Laravel Information kicks ass!"
$blasp->getCleanString(); // "Laravel Information kicks ***!"
$blasp->hasProfanity(); // true
$blasp->getProfanitiesCount(); // 1
$blasp->getUniqueProfanitiesFound(); // ['ass']
In addition to straight matches, this bundle additionally matches varied like substitution (i.e., a$$
), obscured profanity (i.e., a-s-s
), repeated letters, and combos of all of them. Together with the Blasp
facade, this bundle offers a validation rule you should utilize to validate kind enter for profanity:
$validated = $request->validate([
'sentence' => ['blasp_check'],
]);
// If the sentence incorporates profanities, validation will fail.
You’ll be able to study extra about this bundle, get full set up directions, and consider the supply code on GitHub.