yasser-elgammal/pure-text 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

yasser-elgammal/pure-text

最新稳定版本:1.0.3

Composer 安装命令:

composer require yasser-elgammal/pure-text

包简介

Filter Bad Words

README 文档

README

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. With a simple setup and flexible configuration, this package is ideal for applications requiring automatic content moderation.

Features

  • Automatic Filtering: Automatically filters designated model attributes upon saving.
  • Customizable Words List: Easily modify the list of inappropriate words and replacements from the config file.
  • Language Support: Works with multiple languages, including Arabic and other non-Latin character sets.
  • Trait Integration: Apply the Filterable trait to models, specifying which attributes should be filtered.
  • Service Provider Configuration: Provides easy configuration via a service provider and includes a singleton service for optimal performance.
  • Custom Validation Rule: pure_text

Installation

  1. Install the package via Composer:

    composer require yasser-elgammal/pure-text
  2. Publish the configuration file:

    php artisan vendor:publish --provider="YasserElgammal\PureText\PureTextServiceProvider"
  3. Configure your list of words to filter in the config/badwords.php file.

Usage

  1. Add the Trait to Your Model

    Use the PureTextFilterable trait in any model where you need to filter specific attributes.

    use YasserElgammal\PureText\Traits\PureTextFilterable;
    
    class Post extends Model
    {
        use PureTextFilterable;
    
        protected $filterable = ['title', 'content'];
    }
  2. Configuring Filterable Attributes

    Define protected $filterable on the model with an array of attribute names you want to filter.

Configuration

The configuration file badwords.php allows you to define:

  • words: An array of bad words that should be filtered.
  • replacement: The replacement text for filtered words, defaulting to ***.

Example

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 ***

Other Usage :: With Custom Validation Rule: pure_text

This package provides a custom validation rule pure_text
that checks if the given text contains prohibited words using PureTextFilterService
and prevents the creation or update if prohibited words are found.

$request->validate([
    'content' => 'required|pure_text'
]);

## Contributing

Contributions are welcome! Please fork this repository and submit a pull request for any improvements.

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-08