PHPackages                             diego-ninja/laravel-censor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. diego-ninja/laravel-censor

Abandoned → [diego-ninja/sentinel](/?search=diego-ninja%2Fsentinel)Library[Utility &amp; Helpers](/categories/utility)

diego-ninja/laravel-censor
==========================

A content moderation and sentiment analysis library for Laravel 10+

v2.2.0(9mo ago)385452[3 PRs](https://github.com/diego-ninja/sentinel/pulls)MITPHPPHP ^8.3CI passing

Since Dec 4Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/diego-ninja/sentinel)[ Packagist](https://packagist.org/packages/diego-ninja/laravel-censor)[ Docs](https://github.com/diego-ninja/sentinel)[ Fund](https://paypal.me/diegorin)[ Fund](https://ko-fi.com/diegoninja)[ RSS](/packages/diego-ninja-laravel-censor/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (21)Versions (20)Used By (0)

Sentinel for Laravel
====================

[](#sentinel-for-laravel)

 [![Sentinel Logo](./.github/assets/logo.png)](./.github/assets/logo.png)

[![Laravel Package](https://camo.githubusercontent.com/45a4d445368f7ee118c3e18659542f387feeef10fc8872c2640c8566fec488fa/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c25323031302b2532305061636b6167652d7265643f6c6f676f3d6c61726176656c266c6f676f436f6c6f723d7768697465267374796c653d666c61742d737175617265)](https://www.laravel.com)[![Latest Version on Packagist](https://camo.githubusercontent.com/f6c258b9accc394881c129d1886545d0968ce898d5f4d5cee0195af1fdefdfe9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646965676f2d6e696e6a612f73656e74696e656c2e7376673f7374796c653d666c61742d73717561726526636f6c6f723d626c7565266c6f676f436f6c6f723d253233393439636134266c6162656c436f6c6f723d253233336634373530)](https://packagist.org/packages/diego-ninja/sentinel)[![Total Downloads](https://camo.githubusercontent.com/de24f3ea6c563bfc36fcf1fc26f34785f60d1437d73c1790c31fb85b47bdace7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646965676f2d6e696e6a612f73656e74696e656c2e7376673f7374796c653d666c61742d73717561726526636f6c6f723d626c7565266c6f676f436f6c6f723d253233393439636134266c6162656c436f6c6f723d253233336634373530)](https://packagist.org/packages/diego-ninja/sentinel)[![PHP Version](https://camo.githubusercontent.com/a94ec8f96ee572e547c24c0f191ec62370b670355060f8bab7680fa00973f738/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646965676f2d6e696e6a612f73656e74696e656c2e7376673f7374796c653d666c61742d73717561726526636f6c6f723d626c7565266c6f676f436f6c6f723d253233393439636134266c6162656c436f6c6f723d253233336634373530)](https://camo.githubusercontent.com/a94ec8f96ee572e547c24c0f191ec62370b670355060f8bab7680fa00973f738/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646965676f2d6e696e6a612f73656e74696e656c2e7376673f7374796c653d666c61742d73717561726526636f6c6f723d626c7565266c6f676f436f6c6f723d253233393439636134266c6162656c436f6c6f723d253233336634373530)[![License: MIT](https://camo.githubusercontent.com/76fe2092d35371ec80a7aa2e57d649bf28726f186b3198e8c013b52e59c9885b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d73717561726526636f6c6f723d626c7565266c6f676f436f6c6f723d253233393439636134266c6162656c436f6c6f723d253233336634373530)](https://opensource.org/licenses/MIT)[![GitHub last commit](https://camo.githubusercontent.com/cd1b2e1d00df09f60f987b93e3a1a5e844dabc1843b3e23868d77b7071e6544b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f646965676f2d6e696e6a612f73656e74696e656c3f7374796c653d666c61742d73717561726526636f6c6f723d626c7565266c6f676f436f6c6f723d253233393439636134266c6162656c436f6c6f723d253233336634373530)](https://camo.githubusercontent.com/cd1b2e1d00df09f60f987b93e3a1a5e844dabc1843b3e23868d77b7071e6544b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f646965676f2d6e696e6a612f73656e74696e656c3f7374796c653d666c61742d73717561726526636f6c6f723d626c7565266c6f676f436f6c6f723d253233393439636134266c6162656c436f6c6f723d253233336634373530)[![wakatime](https://camo.githubusercontent.com/8311cc438d66ec7ed09394cb3a83dc91d7c2be320ec18f3f8e74804209f02856/68747470733a2f2f77616b6174696d652e636f6d2f62616467652f757365722f62643635663035352d633966332d346637332d393261612d3363393831306637306363332f70726f6a6563742f37623935303630302d326539652d343636302d393036612d6538663635663535353737382e7376673f7374796c653d666c61742d73717561726526636f6c6f723d626c7565266c6f676f436f6c6f723d253233393439636134266c6162656c436f6c6f723d253233336634373530)](https://wakatime.com/badge/user/bd65f055-c9f3-4f73-92aa-3c9810f70cc3/project/7b950600-2e9e-4660-906a-e8f65f555778)

![Tests](https://camo.githubusercontent.com/77040f409e99129572c82e157ddbddff3111701ae1e3ba956082364ee4c48cf2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f646965676f2d6e696e6a612f73656e74696e656c2f74657374732e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265266c6f676f3d676974687562266c6162656c3d506573742532305465737473266c6f676f436f6c6f723d253233393439636134266c6162656c436f6c6f723d253233336634373530)![Static Analysis](https://camo.githubusercontent.com/f4e140a96fe2a456fc58154e71ee652ca302f29987fc7ac14cfa3dfcc4974322/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f646965676f2d6e696e6a612f73656e74696e656c2f7374617469632d616e616c797369732e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265266c6f676f3d676974687562266c6162656c3d5048505374616e2532303130266c6f676f436f6c6f723d253233393439636134266c6162656c436f6c6f723d253233336634373530)![Code Style](https://camo.githubusercontent.com/81c8dcab8bf804206ba9ce4ceccf59f63f0d42863e30b9721f6031ee2b333013/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f646965676f2d6e696e6a612f73656e74696e656c2f636f64652d7374796c652e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265266c6f676f3d676974687562266c6162656c3d50696e74253341253230504552266c6f676f436f6c6f723d253233393439636134266c6162656c436f6c6f723d253233336634373530)![Coveralls](https://camo.githubusercontent.com/67eb803284eb71cc786493b5c5eb26a39d9e7ed3d42c5a97f7e64b24169417dd/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c73436f7665726167652f6769746875622f646965676f2d6e696e6a612f73656e74696e656c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265266c6f676f3d636f766572616c6c73266c6f676f436f6c6f723d253233393439636134266c6162656c436f6c6f723d253233336634373530266c696e6b3d6874747073253341253246253246636f766572616c6c732e696f253246676974687562253246646965676f2d6e696e6a612532466772616e697465)

🚀 Introduction
--------------

[](#-introduction)

Sentinel is an advanced, flexible, and powerful content analysis package for Laravel applications. It provides comprehensive protection against offensive content through multiple detection strategies, context-aware analysis, and multilingual support.

This documentation has been generated almost in its entirety using 🦠 [Claude 3.5 Haiku](https://claude.ai/) based on source code analysis. Some sections may be incomplete, outdated or may contain documentation for planned or not-released features. For the most accurate information, please refer to the source code or open an issue on the package repository.

❤️ Features
-----------

[](#️-features)

- Multiple service providers support:

    - Local dictionary-based analysis
    - [Tisane AI](https://tisane.ai/)
    - [Prism LLM](https://prism.echolabs.dev/) (with support for multiple LLMs)
    - [Azure AI](https://azure.microsoft.com/en-us/pricing/details/cognitive-services/content-safety/)
    - [Perspective AI](https://perspectiveapi.com/)
- Advanced detection strategies:

    - Exact match with Trie indexing
    - Pattern matching with character substitutions
    - N-gram analysis for phrase detection
    - Variation detection for obfuscated content
    - Repeated character detection
    - Levenshtein distance matching
    - Alphanumeric variation detection
    - Phonetic matching
    - Zero-width character detection
    - Reversed word detection
- Rich analysis results:

    - Sentiment analysis
    - Content categorization
    - Match position tracking
    - Context and confidence scoring
- Multi-language support
- Whitelist functionality
- Configurable dictionaries
- Laravel Facade and helper functions
- Laravel validation rule
- Caching system
- Full Octane compatibility

Planned Features
----------------

[](#planned-features)

- Unicode support enhancement
- More service providers
- Machine learning enhancements

📦 Installation
--------------

[](#-installation)

You can install the package via composer:

```
composer require diego-ninja/sentinel
```

After installing, publish the configuration file and dictionaries:

```
php artisan vendor:publish --tag="sentinel-config"
php artisan vendor:publish --tag="sentinel-dictionaries"
```

🎛️ Configuration
----------------

[](#️-configuration)

The package configuration file will be published at `config/sentinel.php`. Here you can configure:

- Default language and available languages
- Default profanity service
- Mask character for moderated words
- Character replacements for evasion detection
- Whitelisted words
- Dictionary path
- Service-specific configurations
- Cache settings
- Analysis thresholds

### API Keys Configuration

[](#api-keys-configuration)

Some services require API keys. Add these to your `.env` file:

```
SENTINEL_THRESHOLD_SCORE=0.5
SENTINEL_CACHE_ENABLED=true
SENTINEL_CACHE_TTL=3600
SENTINEL_CACHE_STORE=redis

PERSPECTIVE_AI_API_KEY=your-perspective-api-key
TISANE_AI_API_KEY=your-tisane-api-key
AZURE_AI_API_KEY=your-azure-api-key
AZURE_AI_ENDPOINT=your-azure-endpoint

# Prism Configuration
PRISM_PROVIDER=anthropic
PRISM_MODEL=claude-3-sonnet-latest
```

⚙️ Basic Usage
--------------

[](#️-basic-usage)

You can use Sentinel in three ways:

### 1. Facade

[](#1-facade)

```
use Ninja\Sentinel\Facades\Sentinel;

// Check if text contains offensive content
$isOffensive = Sentinel::offensive('some text');

// Get cleaned version of text
$cleanText = Sentinel::clean('some text');

// Get detailed analysis with sentiment and matches
$result = Sentinel::check('some text');

// Use a specific provider
$result = Sentinel::with(Provider::Prism, 'some text');
```

### 2. Helper Functions

[](#2-helper-functions)

```
// Check if text is offensive
$isOffensive = is_offensive('some text');

// Clean offensive content
$cleanText = clean('some text');
```

### 3. Validation Rule

[](#3-validation-rule)

```
$rules = [
    'comment' => ['required', 'string', 'offensive']
];
```

Available Moderation Providers
------------------------------

[](#available-moderation-providers)

### Local Provider

[](#local-provider)

Uses local dictionaries with multiple detection strategies for offline profanity checking.

```
use Ninja\Sentinel\Enums\Provider;

$result = Sentinel::with(Provider::Local, 'text to check');
```

Features:

- Multiple detection strategies
- Fast performance
- No API dependencies
- Configurable pattern matching

### PurgoMalum

[](#purgomalum)

Free web service for basic profanity filtering.

```
$result = Sentinel::with(Provider::PurgoMalum, 'text to check');
```

### Azure AI Content Safety

[](#azure-ai-content-safety)

Uses Azure's AI content moderation service with advanced content analysis.

```
$result = Sentinel::with(Provider::Azure, 'text to check');
```

### Perspective AI

[](#perspective-ai)

Uses Google's Perspective API for toxicity and content analysis.

```
$result = Sentinel::with(Provider::Perspective, 'text to check');
```

### Tisane AI

[](#tisane-ai)

Natural language processing service for content moderation.

```
$result = Sentinel::with(Provider::Tisane, 'text to check');
```

### Prism LLM Support

[](#prism-llm-support)

Access various Large Language Models through Prism:

```
use Ninja\Sentinel\Enums\Provider;

$result = Sentinel::with(Provider::Prism, 'text to check');
```

Supported models through Prism:

- Anthropic (Claude models)
- OpenAI (GPT models)
- Gemini
- Mistral
- Ollama
- DeepSeek
- Groq
- xAI

Working with Results
--------------------

[](#working-with-results)

All services return a Result object with consistent methods:

```
$result = Sentinel::check('some text');

// Basic information
$result->offensive();    // bool: whether the text contains offensive content
$result->words();        // array: list of matched offensive words
$result->replaced();     // string: text with offensive words replaced
$result->original();     // string: original text
$result->score();        // Score: offensive content score
$result->confidence();   // Confidence: confidence level

// Detailed analysis
$result->sentiment();    // Sentiment: text sentiment analysis
$result->categories();   // array: detected content categories

// Match information
$result->matches();      // MatchCollection: detailed matches with positions
```

### Working with Matches

[](#working-with-matches)

The MatchCollection provides detailed information about each match:

```
$matches = $result->matches();

foreach ($matches as $match) {
    echo "Word: " . $match->word();
    echo "Type: " . $match->type();          // exact, pattern, variation, etc.
    echo "Score: " . $match->score();
    echo "Confidence: " . $match->confidence();

    // Get all occurrences of the match
    foreach ($match->occurrences() as $occurrence) {
        echo "Position: " . $occurrence->start();
        echo "Length: " . $occurrence->length();
    }

    // Context information if available
    if ($context = $match->context()) {
        echo "Original form: " . $context['original'];
        echo "Surrounding text: " . $context['surrounding'];
    }
}
```

### Categories

[](#categories)

The package can detect various content categories:

```
use Ninja\Sentinel\Enums\Category;

$categories = $result->categories();
// Can include:
// - Category::HateSpeech
// - Category::Harassment
// - Category::Sexual
// - Category::Violence
// - Category::Threat
// - Category::Toxicity
// - Category::Profanity
```

### Sentiment Analysis

[](#sentiment-analysis)

Results include sentiment analysis when available:

```
$sentiment = $result->sentiment();

echo $sentiment->type();    // positive, negative, neutral, mixed
echo $sentiment->score();   // -1.0 to 1.0
```

Response Caching
----------------

[](#response-caching)

External service responses are automatically cached to improve performance and reduce API calls. By default, all external services will cache their responses for 1 hour.

The local provider is not cached as it's already performant enough.

### Configuring Cache

[](#configuring-cache)

You can configure the cache in your `.env` file:

```
SENTINEL_CACHE_ENABLED=true # Enable caching (default: true)
SENTINEL_CACHE_TTL=3600 # Cache duration in seconds (default: 1 hour)
SENTINEL_CACHE_STORE=redis # Cache store (default: file)
```

Or in your `config/sentinel.php`:

```
    'cache' => [
        'enabled' => env('SENTINEL_CACHE_ENABLED', true),
        'store' => env('SENTINEL_CACHE_STORE', 'file'),
        'ttl' => env('SENTINEL_CACHE_TTL', 60),
    ],
```

### Cache Keys

[](#cache-keys)

Cache keys are generated using the following format:

```
sentinel:{ServiceName}:{md5(text)}

```

Detection Strategies
--------------------

[](#detection-strategies)

The local checker uses a multi-strategy approach to detect offensive content accurately. Each piece of text is processed through different detection strategies in sequence:

1. **Trie Index Strategy**: Fast exact matching using a Trie data structure
2. **Pattern Strategy**: Handles exact matches and character substitutions
3. **NGram Strategy**: Detects offensive phrases by analyzing word combinations
4. **Variation Strategy**: Catches attempts to evade detection through character separation
5. **Repeated Chars Strategy**: Identifies words with intentionally repeated characters
6. **Levenshtein Strategy**: Uses string distance comparison for similar words

Each strategy can operate in either full word or partial matching mode. Results from all strategies are combined, deduplicated, and scored based on the type and quantity of matches found.

Custom Dictionaries
-------------------

[](#custom-dictionaries)

You can add your own dictionaries or modify existing ones:

1. Create a new PHP file in your `resources/dict` directory
2. Return an array of words to be moderated
3. Update your config to include the new language

```
// resources/dict/custom.php
return [
    'word1',
    'word2',
    // ...
];

// config/sentinel.php
'languages' => ['en', 'custom'],
```

Whitelist
---------

[](#whitelist)

You can whitelist words to prevent them from being moderated:

```
// config/sentinel.php
'whitelist' => [
    'word1',
    'word2',
],
```

Character Substitution
----------------------

[](#character-substitution)

The package detects common character substitutions. Configure these in:

```
// config/sentinel.php
'replacements' => [
    'a' => '(a|@|4)',
    'i' => '(i|1|!)',
    // ...
],
```

🙏 Credits
---------

[](#-credits)

This project is developed and maintained by 🥷 [Diego Rin](https://diego.ninja) in his free time.

Special thanks to:

- [Laravel Framework](https://laravel.com/) for providing the most exciting and well-crafted PHP framework.
- [Snipe](https://github.com/snipe) for developing the [initial code](https://github.com/snipe/banbuilder) that serves Sentinel as starting point.
- All the contributors and testers who have helped to improve this project through their contributions.

If you find this project useful, please consider giving it a ⭐ on GitHub!

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance82

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 89% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~20 days

Recently: every ~40 days

Total

13

Last Release

277d ago

Major Versions

v1.3.0 → v2.0.02025-02-20

PHP version history (2 changes)v1.0.0PHP ^8.2

v1.3.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/dff5b0a76de3d555cb236c400384058ba23982bce2e859cc1b2f0c1f0161a3e6?d=identicon)[diego.ninja](/maintainers/diego.ninja)

---

Top Contributors

[![diego-ninja](https://avatars.githubusercontent.com/u/78662279?v=4)](https://github.com/diego-ninja "diego-ninja (89 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")[![eviera22](https://avatars.githubusercontent.com/u/28775993?v=4)](https://github.com/eviera22 "eviera22 (4 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")

---

Tags

ai-poweredcontent-moderationlaravellaravel-framework-10laravel-packagephp-libraryphp8sentiment-analysistext-filteringlaravellanguagecontentstringsfilterprofanitymoderationswear

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/diego-ninja-laravel-censor/health.svg)

```
[![Health](https://phpackages.com/badges/diego-ninja-laravel-censor/health.svg)](https://phpackages.com/packages/diego-ninja-laravel-censor)
```

###  Alternatives

[diego-ninja/sentinel

A content moderation and sentiment analysis library for Laravel 10+

384.3k](/packages/diego-ninja-sentinel)[snipe/banbuilder

Library to easily handle profanity filtering in PHP projects.

3371.5M3](/packages/snipe-banbuilder)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)[bensampo/laravel-embed

Painless responsive embeds for videos, slideshows and more.

142146.8k](/packages/bensampo-laravel-embed)[glhd/conveyor-belt

14797.0k](/packages/glhd-conveyor-belt)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
