blaspsoft/blasp
Advanced profanity filtering for Laravel with driver-based detection (regex/pattern/phonetic/pipeline), multi-language support, severity scoring, masking strategies, Eloquent trait, middleware and validation rules, events, and test fakes. Powers blasp.app API.
DriverInterface, enabling domain-specific adaptations (e.g., industry jargon, niche slang).Blaspable trait reduces boilerplate for model-level filtering, though it assumes models are saved via create()/update() (not raw queries).@clean directive simplifies view-layer sanitization, but requires template updates.metaphone() + Levenshtein, which may slow down bulk operations.config/blasp.cache.enabled = true) or use the lighter pattern driver for low-severity checks.max_distance_ratio) may flag innocuous words (e.g., "fork" → "fuck"). Custom false_positives lists help but require maintenance.f-u-u-u-c-k).config/blasp.drivers.phonetic.false_positives.php artisan vendor:publish --tag="blasp-languages") adds complexity.pattern driver first for baseline performance.Severity), and attributes (e.g., for custom drivers).grawlix) may need UI adjustments.composer require blaspsoft/blasp.php artisan vendor:publish --tag="blasp".CommentController).use Blaspsoft\Blasp\Rules\Profanity;
$request->validate(['body' => ['required', Profanity::in('english')->minSeverity('high')]]);
blasp:sanitize) to high-risk routes.Blaspable trait to critical models (e.g., Post, UserBio).blaspable attributes and mode (sanitize/reject).@clean directive.blasp.cache.enabled = true) for production.Blasp::check() for consistency.allow/block lists in config to merge with existing rules.Str macros (e.g., Str::isProfane may shadow other macros).| Phase | Tasks | Risk Level | Rollback Plan |
|---|---|---|---|
| Config Setup | Publish config, adjust blasp.php for your needs. |
Low | Revert config to defaults. |
| Validation Rules | Add blasp_check to form requests. |
Low | Remove validation rules. |
| Middleware | Apply blasp:sanitize to high-risk routes. |
Medium | Remove middleware from RouteServiceProvider. |
| Eloquent Models | Add Blaspable trait to models. |
Medium | Remove trait, revert to manual checks. |
| Blade Updates | Replace raw {{ $var }} with @clean($var). |
Low | Revert templates. |
| Caching | Enable blasp.cache.enabled = true in production. |
Low | Disable caching. |
| Custom Drivers | Implement DriverInterface for niche use cases. |
High | Remove custom driver registration. |
blasp.php) reduces maintenance but requires coordination across teams.severity set to high in production).php artisan vendor:publish --tag="blasp-languages").Blaspsoft/blasp for new language releases.false_positives list may need updates as slang evolves.Blasp::fake() in tests to simulate profanity detection.ProfanityDetected events for auditing:
Event::listen(ProfanityDetected::class, function ($event) {
\Log::debug('Profanity detected', $event->result->toArray());
});
reject mode, provide clear error messages (e.g., "Your comment contains prohibited language").return response()->json([
'message' => 'Profanity detected in field: ' . $attribute,
'details' => $result->uniqueWords(),
], 422);
Blasp::inAllLanguages()->check($text);
blasp.cache.results = true).pattern driver for low-severity checks.How can I help you explore Laravel packages today?