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.
Install the package via Composer:
composer require yasser-elgammal/pure-text
Publish the configuration file:
php artisan vendor:publish --provider="YasserElgammal\PureText\PureTextServiceProvider"
Configure your list of words to filter in the config/badwords.php file.
Use the PureTextFilterable trait in any model where you need to filter specific attributes.
```php use YasserElgammal\PureText\Traits\PureTextFilterable; class Post extends Model { use PureTextFilterable; protected $filterable = ['title', 'content']; } ```
Define protected $filterable on the model with an array of attribute names you want to filter.
The configuration file badwords.php allows you to define:
Here's a basic example of usage in a controller:
$post = new Post(); $post->title = "This is a badword example"; $post->content = "Some more text with badword"; $post->save(); echo $post->title; // Outputs: This is a ***
Github Link
I would greatly appreciate your support by giving it a star.
Thanks ?
The above is the detailed content of Pure Text Laravel Package. For more information, please follow other related articles on the PHP Chinese website!