Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Yasser Elgammal
Yasser Elgammal

Posted on

     

Pure Text Laravel Package

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.


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 theFilterable 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.

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 theconfig/badwords.php file.

Usage

  1. Add the Trait to Your Model

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

```phpuse YasserElgammal\PureText\Traits\PureTextFilterable;class Post extends Model{    use PureTextFilterable;    protected $filterable = ['title', 'content'];}```
Enter fullscreen modeExit fullscreen mode
  1. Configuring Filterable Attributes

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

Configuration

The configuration filebadwords.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=newPost();$post->title="This is a badword example";$post->content="Some more text with badword";$post->save();echo$post->title;// Outputs: This is a ***
Enter fullscreen modeExit fullscreen mode

Github Link

I would greatly appreciate your support by giving it a star.

Thanks 💚

Top comments(1)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
mmramadan496 profile image
Mahmoud Ramadan
Computer Science Geek 🧐 || Software Engineer 👨‍💻 || Digging Code Creator 🚀
  • Location
    Mansoura, Dakahlia, Egypt
  • Education
    Mansoura University
  • Joined

Congrats!

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Software engineer @ AAIT
  • Location
    Egypt, Damietta
  • Work
    Software Engineer | Backend Developer | PHP | Laravel | Fintech
  • Joined

More fromYasser Elgammal

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp