Download the PHP package yasser-elgammal/pure-text without Composer
On this page you can find all versions of the php package yasser-elgammal/pure-text. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yasser-elgammal/pure-text
More information about yasser-elgammal/pure-text
Files in yasser-elgammal/pure-text
Package pure-text
Short Description A Laravel package for filtering and replacing inappropriate or unwanted words with support for Arabic and Unicode, multiple replacement strategies, Blade directives, middleware, and more.
License MIT
Homepage https://github.com/YasserElgammal/pure-text
Informations about the package pure-text
PureText
PureText is a Laravel package for filtering and replacing inappropriate or unwanted words within model attributes automatically. Designed to be customizable and efficient, PureText allows developers to specify filterable attributes for each model and handle multiple languages seamlessly — including Arabic and other Unicode languages.
✨ Features
- Automatic Model Filtering — Apply the
PureTextFilterabletrait and bad words are filtered on save. - Multiple Replacement Strategies — Choose between
fixed,character, orlength_matchreplacements. - Unicode & Arabic Support — Proper Unicode-aware word boundaries for non-Latin languages.
- Evasion Detection — Catches common tricks like
b-a-d,b_a_d,b.a.d. - Facade —
PureText::filter(),PureText::containsBadWords(),PureText::getBadWords(). - Blade Directive —
@pureText($text)for templates. - Middleware — Filter request fields automatically via route middleware.
- Validation Rule —
pure_textrule for Laravel Validator. - Helper Functions —
pure_text()andhas_bad_words()global helpers. - Events —
TextFilteredevent dispatched on model attribute filtering. - Customizable — Bring your own implementation via
TextFilterInterface.
📋 Requirements
- PHP 8.1+
- Laravel 10, 11, or 12
📦 Installation
Install via Composer:
Publish the configuration file:
Configure your word list in config/badwords.php.
🚀 Usage
1. Automatic Model Filtering (Trait)
Add the PureTextFilterable trait to any model and define $filterable attributes:
Now, bad words are automatically replaced when saving:
2. Facade
3. Blade Directive
4. Validation Rule
5. Middleware
Register in your route:
6. Helper Functions
⚙️ Configuration
After publishing, edit config/badwords.php:
Replacement Strategies
| Strategy | Input | Output | Description |
|---|---|---|---|
fixed |
badword |
*** |
Replaces with the replacement value |
character |
badword |
******* |
Each character replaced with character |
length_match |
badword |
******* |
First char of replacement repeated to match length |
🔌 Advanced: Custom Implementation
You can swap the filter service with your own by binding TextFilterInterface:
📡 Events
When a model attribute is filtered via the PureTextFilterable trait, a TextFiltered event is dispatched:
🧪 Testing
📄 Changelog
Please see CHANGELOG.md for recent changes.
🤝 Contributing
Contributions are welcome! Please fork this repository and submit a pull request for any improvements.
📜 License
The MIT License (MIT). Please see LICENSE for more information.
All versions of pure-text with dependencies
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/validation Version ^10.0|^11.0|^12.0