Download the PHP package blaspsoft/blasp without Composer
On this page you can find all versions of the php package blaspsoft/blasp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download blaspsoft/blasp
More information about blaspsoft/blasp
Files in blaspsoft/blasp
Package blasp
Short Description Blasp is a powerful and customisable profanity filter package for Laravel applications
License MIT
Homepage https://github.com/blaspsoft/blasp
Informations about the package blasp
Blasp - Advanced Profanity Filter for Laravel
Blasp is a powerful, extensible profanity filter for Laravel. Version 4 is a ground-up rewrite with a driver-based architecture, severity scoring, masking strategies, Eloquent model integration, and a clean fluent API.
Features
- Driver Architecture —
regex(detects obfuscation, substitutions, separators),pattern(fast exact matching),phonetic(catches sound-alike evasions), orpipeline(chains multiple drivers together). Extend with custom drivers. - Multi-Language — English, Spanish, German, French with language-specific normalizers. Check one, many, or all at once.
- Severity Scoring — Words categorised as mild/moderate/high/extreme. Filter by minimum severity and get a 0-100 score.
- Masking Strategies — Character mask (
*,#), grawlix (!@#$%), or a custom callback. - Eloquent Integration —
Blaspabletrait auto-sanitizes or rejects profanity on model save. - Middleware — Reject or sanitize profane request fields with configurable severity.
- Validation Rules — Fluent validation rule with language, severity, and score threshold support.
- Testing Utilities —
Blasp::fake()for test doubles with assertions. - Events —
ProfanityDetected,ContentBlocked, andModelProfanityDetected.
Requirements
- PHP 8.2+
- Laravel 8.0+
Installation
Publish configuration:
Quick Start
Fluent API
All builder methods return a PendingCheck and can be chained:
Result Object
The Result object is returned by every check() call:
| Method | Returns | Description |
|---|---|---|
isOffensive() |
bool |
Text contains profanity |
isClean() |
bool |
Text is clean |
clean() |
string |
Text with profanities masked |
original() |
string |
Original unmodified text |
score() |
int |
Severity score (0-100) |
count() |
int |
Total profanity matches |
uniqueWords() |
array |
Unique base words detected |
severity() |
?Severity |
Highest severity in matches |
words() |
Collection |
MatchedWord objects with position, length, severity |
toArray() |
array |
Full result as array |
toJson() |
string |
Full result as JSON |
Result implements JsonSerializable, Stringable (returns clean text), and Countable.
Detection Types
The regex driver detects obfuscated profanity:
| Type | Example | Detected As |
|---|---|---|
| Straight match | fucking |
fucking |
| Substitution | fÛck!ng, f4ck |
fucking, fuck |
| Separators | f-u-c-k-i-n-g, f@ck |
fucking, fuck |
| Doubled | ffuucckkiinngg |
fucking |
| Combination | f-uuck!ng |
fucking |
Separator limit: The regex driver allows up to 3 separator characters between each letter (e.g.,
f--u--c--k). This covers all realistic obfuscation patterns while keeping regex complexity low enough for PHP-FPM environments.
The pattern driver only detects straight word-boundary matches.
The phonetic driver uses metaphone() + Levenshtein distance to catch words that sound like profanity but are spelled differently:
| Type | Example | Detected As |
|---|---|---|
| Phonetic spelling | phuck |
fuck |
| Shortened form | fuk |
fuck |
| Sound-alike | sheit |
shit |
Configure sensitivity in config/blasp.php under drivers.phonetic. A curated false-positive list prevents common words like "fork", "duck", and "beach" from being flagged.
Pipeline Driver
The pipeline driver chains multiple drivers together so a single check() call runs all of them. It uses union merge semantics — text is flagged if any driver finds a match.
When multiple drivers detect the same word at the same position, duplicates are removed — only the longest match is kept. Masks are applied from the merged result, and the score is recalculated across all matches.
Configure the default sub-drivers in config/blasp.php:
Eloquent Integration
The Blaspable trait automatically checks model attributes during save:
Per-Model Overrides
Reject Mode
In reject mode, saving a model with profanity throws ProfanityRejectedException and the model is not persisted:
Disabling Checking
Events
A ModelProfanityDetected event fires whenever profanity is detected on a model attribute (both sanitize and reject modes):
Middleware
Use CheckProfanity to filter incoming request fields. A blasp middleware alias is registered automatically:
| Action | Behaviour |
|---|---|
reject (default) |
Returns 422 JSON with field errors |
sanitize |
Replaces profane fields in the request and continues |
Configure which fields to check in config/blasp.php:
Validation Rules
String Rule
Fluent Rule Object
Blade Directive
The @clean directive sanitizes and escapes text for safe display in views:
Output is HTML-escaped via e() for XSS safety.
Str / Stringable Macros
Blasp registers macros on Laravel's Str and Stringable classes:
Configuration
Full config/blasp.php reference:
Custom Drivers
Implement DriverInterface and register with the manager:
Caching
Blasp caches check() results by default. When the same text is checked with the same configuration (language, driver, severity, allow/block lists), the cached result is returned instantly.
Configure caching in config/blasp.php:
Result caching is automatically bypassed when using a CallbackMask (closures can't be serialized). Clear both dictionary and result caches with:
Or programmatically:
Artisan Commands
Testing
Faking
Disabling Filtering
Events
Enable global events with 'events' => true in config:
| Event | Fired When | Properties |
|---|---|---|
ProfanityDetected |
check() finds profanity |
result, originalText |
ContentBlocked |
Middleware detects profanity | result, request, field, action |
ModelProfanityDetected |
Blaspable trait detects profanity | model, attribute, result |
ModelProfanityDetected always fires (not gated by the events config).
Migrating from v3
Namespace Changes
| v3 | v4 |
|---|---|
Blaspsoft\Blasp\Facades\Blasp |
Blaspsoft\Blasp\Facades\Blasp (unchanged) |
Blaspsoft\Blasp\ServiceProvider |
Blaspsoft\Blasp\BlaspServiceProvider |
The Laravel auto-discovery handles provider/alias registration automatically. The facade namespace is the same as v3, so no import changes are needed for the facade.
Config Changes
| v3 Key | v4 Key | Notes |
|---|---|---|
default_language |
language |
default_language still works as alias |
mask_character |
mask |
mask_character still works as alias |
cache_driver |
cache.driver |
cache_driver still works as alias |
| — | default |
New: driver selection (regex/pattern) |
| — | severity |
New: minimum severity level |
| — | events |
New: enable global events |
| — | allow / block |
New: global allow/block lists |
| — | middleware |
New: middleware configuration section |
| — | model |
New: Blaspable trait configuration |
Result API Changes
| v3 Method | v4 Method |
|---|---|
hasProfanity() |
isOffensive() |
getCleanString() |
clean() |
getSourceString() |
original() |
getProfanitiesCount() |
count() |
getUniqueProfanitiesFound() |
uniqueWords() |
All v3 methods still work as deprecated aliases.
Builder API Changes
| v3 Method | v4 Method |
|---|---|
maskWith($char) |
mask($char) |
allLanguages() |
inAllLanguages() |
language($lang) |
in($lang) |
configure($profanities, $falsePositives) |
block(...$words) / allow(...$words) |
All v3 methods still work as deprecated aliases.
New in v4
- Driver architecture —
regexandpatterndrivers, custom driver support - Severity system — Mild/Moderate/High/Extreme levels with scoring
- Masking strategies — Grawlix and callback masking
- Blaspable trait — Automatic Eloquent model profanity checking
- Middleware — Request-level profanity filtering
- Fluent validation rule —
Profanity::in('spanish')->severity(Severity::High) - Testing utilities —
Blasp::fake(), assertions,withoutFiltering() - Events —
ProfanityDetected,ContentBlocked,ModelProfanityDetected - Artisan commands —
blasp:clear,blasp:test,blasp:languages - Batch checking —
Blasp::checkMany([...]) - Multi-language in one call —
Blasp::in('english', 'spanish')->check($text)
Contributing
We welcome contributions! Please see our Contributing Guide for details.
Changelog
See CHANGELOG.md for detailed version history.
License
Blasp is open-sourced software licensed under the MIT license.