Level 75
Thanks for sharing this.
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Laravel Blacklist is a Laravel package for blacklist validation of user input. Includes both system blacklist words and profanity/offensive terms, with the flexibility to choose which lists to use. Uses whole word matching to prevent false positives.
The source config file consist of ~70 blacklist words and ~50 profanity words to check against.
The package provides three modes for filtering content:
// config/blacklist.php
return [
// Choose which lists to use: 'blacklist', 'profanity', or 'both'
'mode' => 'blacklist',
// System blacklist words (usernames, reserved terms, etc.)
'blacklist' => [
'admin',
'system',
// ...
],
// Profanity and offensive terms
'profanity' => [
// Common profanity words
// ...
],
];
use Milenmk\LaravelBlacklist\BlacklistService;
class YourController
{
protected BlacklistService $blacklistService;
public function __construct(BlacklistService $blacklistService)
{
$this->blacklistService = $blacklistService;
}
public function store(Request $request)
{
// Validate request...
// Check fields against blacklisted words
$blacklistErrors = $this->blacklistService->checkFields([
'name' => $request->input('name'),
'email' => $request->input('email'),
// Add any other fields you want to check
]);
if (!empty($blacklistErrors)) {
return redirect()->back()->withErrors($blacklistErrors);
}
// Continue with your logic...
}
}
Please or to participate in this conversation.