yosefib/laravel-libyan-badwords

Laravel package to filter and block bad words in Libyan dialect.

Installs: 7

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/yosefib/laravel-libyan-badwords

v1.0.0 2025-09-16 14:19 UTC

This package is not auto-updated.

Last update: 2025-12-24 15:25:55 UTC


README

🌐 Laravel Libyan Bad Words Filter

A lightweight Laravel package to filter and clean Libyan offensive words from text. Supports normalization, diacritics removal, repeated letters, and common spelling variations.

⚙️ Installation

Install via Composer:

composer require yosefib/laravel-libyan-badwords:^1.0

Publish the configuration file (optional, but highly recommended):

php artisan vendor:publish --provider="Yosef\LibyanBadwords\LibyanBadWordsServiceProvider" --tag=config

This will create config/libyan_badwords.php, where you can add your custom list of bad words.

🚀 How to Use

1. Simple Text Filtering

Use the service container to resolve the LibyanBadWordsFilter instance.

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Yosef\LibyanBadwords\LibyanBadWordsFilter;

class MyController extends Controller
{
    public function store(Request $request)
    {
        $text = $request->input('comment');

        // Resolve the filter from the service container
        $filter = app(LibyanBadWordsFilter::class);
        
        // Check if the text contains any bad words
        if ($filter->contains($text)) {
            // If it does, clean the text and get the filtered output
            $cleanText = $filter->clean($text);
            
            // Output: هاذا واحد **** يكتب
            return response()->json(['message' => 'Your text has been filtered.', 'clean_text' => $cleanText]);
        }
        
        // If the text is clean, proceed
        return response()->json(['message' => 'Your text is clean.']);
    }
}

2. Customizing the Replacement

You can pass a custom string to the clean method to use instead of the default ****.

$text = "زآمـلل ومبَعّر";

// Use a custom replacement string
$filter = app(LibyanBadwordsFilter::class);
$censoredText = $filter->clean($text, '[censored]');

// Output: [censored] [censored]

3. Middleware Example

You can use the package within a middleware to automatically clean all incoming request data.

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Yosef\LibyanBadwords\LibyanBadWordsFilter;

class FilterBadWords
{
    public function handle(Request $request, Closure $next)
    {
        // Get the filter instance from the service container
        $filter = app(LibyanBadWordsFilter::class);

        // Filter the 'comment' input field
        if ($filter->contains($request->input('comment'))) {
            $cleanedComment = $filter->clean($request->input('comment'));
            $request->merge(['comment' => $cleanedComment]);
        }

        return $next($request);
    }
}

📝 Configuration

The config/libyan_badwords.php file holds the list of bad words. For optimal performance and accuracy, it's crucial to list words in their normalized form (without diacritics, and with unified letters).

<?php

return [
    'words' => [
        'زامل',
        'مبعر',
        'مفشك',
        'قواد',
        'صرم',
        'اكلا',
        'اكله',
        'اكلة',
        'زوامل',
        'بغل',
        'زبر',
        'زبوب',
        'دلزة',
        'دلاوز',
        'دلزاتي',
        'دلزاتك',
        'صرمك',
        'بزي',
        'بز',
        'بزك',
        'طاقتك',
        'طاقتي',
        'طاقتكم',
        'طواقيكم',
        'مباعر',
        'دلزتي',
        'دلاوزي',
        'نبة',
        'ولد نبة',
        'ولد النبة',
        'كسي',
        'طيزي',
        'منيك',
        'زبر طاقتك',
        'زبر امك',
        'زبور',
        'ميبون',
    ],
];

Add or remove words from this array as needed.

📄 License

MIT License — open-source.