PHPackages                             nguyentranchung/laravel-moderation - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. nguyentranchung/laravel-moderation

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

nguyentranchung/laravel-moderation
==================================

A simple Content Moderation System for Laravel 5.\* that allows you to Approve or Reject resources like posts, comments, users, etc.

v1.1.0(7y ago)081MITPHP &gt;=5.4.0

Since Jan 29Pushed 5y agoCompare

[ Source](https://github.com/nguyentranchung/laravel-moderation)[ Packagist](https://packagist.org/packages/nguyentranchung/laravel-moderation)[ RSS](/packages/nguyentranchung-laravel-moderation/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (3)Versions (16)Used By (0)

Laravel Moderation [![Build Status](https://camo.githubusercontent.com/b2a745b2b9c64a455bb9bf5ee78494d292526d2ed76c5f63d0ca6e8bd57f1748/68747470733a2f2f7472617669732d63692e6f72672f686f6f746c65782f6c61726176656c2d6d6f6465726174696f6e2e7376673f6272616e63683d76312e302e3131)](https://travis-ci.org/hootlex/laravel-moderation) [![Version](https://camo.githubusercontent.com/8ae3907cb2738877eab0679fc6fece21bb5ce56bbd9b2d5a37d50f19aeaaae7b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f686f6f746c65782f6c61726176656c2d6d6f6465726174696f6e2e7376673f7374796c653d666c6174)](https://packagist.org/packages/hootlex/laravel-moderation) [![Total Downloads](https://camo.githubusercontent.com/a3f7d5e333075463d8a2aca01c1d2605d79770616e5c835cb6e0bb0aa1aa6aa1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f686f6f746c65782f6c61726176656c2d6d6f6465726174696f6e2e7376673f7374796c653d666c6174)](https://packagist.org/packages/hootlex/laravel-moderation) [![Software License](https://camo.githubusercontent.com/f251623e510f5909f16ae3f4e6e548dac11340b9fde1a99be26b015b39272c00/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c6174)](LICENSE)
===================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#laravel-moderation-----)

A simple Moderation System for Laravel 5.\* that allows you to Approve or Reject resources like posts, comments, users, etc.

Keep your application pure by preventing offensive, irrelevant, or insulting content.

Possible Use Case
-----------------

[](#possible-use-case)

1. User creates a resource (a post, a comment or any Eloquent Model).
2. The resource is pending and invisible in website (ex. `Post::all()` returns only approved posts).
3. Moderator decides if the resource will be approved, rejected or postponed.
4. **Approved**: Resource is now public and queryable.
5. **Rejected**: Resource will be excluded from all queries. Rejected resources will be returned only if you scope a query to include them. (scope: `withRejected`)
6. **Postponed**: Resource will be excluded from all queries until Moderator decides to approve it.
7. You application is clean.

Installation
------------

[](#installation)

First, install the package through Composer.

```
composer require hootlex/laravel-moderation
```

If you are using Laravel &lt; 5.5, you need to add Hootlex\\Moderation\\ModerationServiceProvider to your `config/app.php` providers array:

```
'providers' => [
    ...
    Hootlex\Moderation\ModerationServiceProvider::class,
    ...
];
```

Lastly you publish the config file.

```
php artisan vendor:publish --provider="Hootlex\Moderation\ModerationServiceProvider" --tag=config

```

Prepare Model
-------------

[](#prepare-model)

To enable moderation for a model, use the `Hootlex\Moderation\Moderatable` trait on the model and add the `status`, `moderated_by` and `moderated_at` columns to your model's table.

```
use Hootlex\Moderation\Moderatable;
class Post extends Model
{
    use Moderatable;
    ...
}
```

Create a migration to add the new columns. [(You can use custom names for the moderation columns)](#configuration)

Example Migration:

```
class AddModerationColumnsToPostsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('posts', function (Blueprint $table) {
            $table->smallInteger('status')->default(0);
            $table->dateTime('moderated_at')->nullable();
            //To track who moderated the Model, add 'moderated_by' and set the column name in the config file.
            //$table->integer('moderated_by')->nullable()->unsigned();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('posts', function(Blueprint $table)
        {
            $table->dropColumn('status');
            $table->dropColumn('moderated_at');
            //$table->dropColumn('moderated_by');
        });
    }
}
```

**You are ready to go!**

Usage
-----

[](#usage)

> **Note:** In next examples I will use Post model to demonstrate how the query builder works. You can Moderate any Eloquent Model, even User.

### Moderate Models

[](#moderate-models)

You can moderate a model Instance:

```
$post->markApproved();

$post->markRejected();

$post->markPostponed();

$post->markPending();
```

or by referencing it's id

```
Post::approve($post->id);

Post::reject($post->id);

Post::postpone($post->id);
```

or by making a query.

```
Post::where('title', 'Horse')->approve();

Post::where('title', 'Horse')->reject();

Post::where('title', 'Horse')->postpone();
```

### Query Models

[](#query-models)

By default only Approved models will be returned on queries. To change this behavior check the [configuration](#configuration).

##### To query the Approved Posts, run your queries as always.

[](#to-query-the-approved-posts-run-your-queries-as-always)

```
//it will return all Approved Posts (strict mode)
Post::all();

// when not in strict mode
Post::approved()->get();

//it will return Approved Posts where title is Horse
Post::where('title', 'Horse')->get();
```

##### Query pending or rejected models.

[](#query-pending-or-rejected-models)

```
//it will return all Pending Posts
Post::pending()->get();

//it will return all Rejected Posts
Post::rejected()->get();

//it will return all Postponed Posts
Post::postponed()->get();

//it will return Approved and Pending Posts
Post::withPending()->get();

//it will return Approved and Rejected Posts
Post::withRejected()->get();

//it will return Approved and Postponed Posts
Post::withPostponed()->get();
```

##### Query ALL models

[](#query-all-models)

```
//it will return all Posts
Post::withAnyStatus()->get();

//it will return all Posts where title is Horse
Post::withAnyStatus()->where('title', 'Horse')->get();
```

### Model Status

[](#model-status)

To check the status of a model there are 3 helper methods which return a boolean value.

```
//check if a model is pending
$post->isPending();

//check if a model is approved
$post->isApproved();

//check if a model is rejected
$post->isRejected();

//check if a model is rejected
$post->isPostponed();
```

Strict Moderation
-----------------

[](#strict-moderation)

Strict Moderation means that only Approved resource will be queried. To query Pending resources along with Approved you have to disable Strict Moderation. See how you can do this in the [configuration](#configuration).

Configuration
-------------

[](#configuration)

### Global Configuration

[](#global-configuration)

To configuration Moderation package globally you have to edit `config/moderation.php`. Inside `moderation.php` you can configure the following:

1. `status_column` represents the default column 'status' in the database.
2. `moderated_at_column` represents the default column 'moderated\_at' in the database.
3. `moderated_by_column` represents the default column 'moderated\_by' in the database.
4. `strict` represents [*Strict Moderation*](#strict-moderation).

### Model Configuration

[](#model-configuration)

Inside your Model you can define some variables to overwrite **Global Settings**.

To overwrite `status` column define:

```
const MODERATION_STATUS = 'moderation_status';
```

To overwrite `moderated_at` column define:

```
const MODERATED_AT = 'mod_at';
```

To overwrite `moderated_by` column define:

```
const MODERATED_BY = 'mod_by';
```

To enable or disable [Strict Moderation](#strict-moderation):

```
public static $strictModeration = true;
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 79.5% 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 ~66 days

Recently: every ~121 days

Total

14

Last Release

2895d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0d0f3c4c484def533574ea61cb98cac3271481ba99fa394be5b48a2195d624d7?d=identicon)[nguyentranchung](/maintainers/nguyentranchung)

---

Top Contributors

[![hootlex](https://avatars.githubusercontent.com/u/6147968?v=4)](https://github.com/hootlex "hootlex (66 commits)")[![zek](https://avatars.githubusercontent.com/u/3463291?v=4)](https://github.com/zek "zek (5 commits)")[![stephane-monnot](https://avatars.githubusercontent.com/u/6066368?v=4)](https://github.com/stephane-monnot "stephane-monnot (5 commits)")[![harrygulliford](https://avatars.githubusercontent.com/u/5051286?v=4)](https://github.com/harrygulliford "harrygulliford (2 commits)")[![GabrielFiel](https://avatars.githubusercontent.com/u/12551784?v=4)](https://github.com/GabrielFiel "GabrielFiel (1 commits)")[![PiranhaGeorge](https://avatars.githubusercontent.com/u/203654?v=4)](https://github.com/PiranhaGeorge "PiranhaGeorge (1 commits)")[![bryant1410](https://avatars.githubusercontent.com/u/3905501?v=4)](https://github.com/bryant1410 "bryant1410 (1 commits)")[![superbiche](https://avatars.githubusercontent.com/u/2478146?v=4)](https://github.com/superbiche "superbiche (1 commits)")[![gecche](https://avatars.githubusercontent.com/u/11093763?v=4)](https://github.com/gecche "gecche (1 commits)")

---

Tags

laravelcontent moderationmoderationmoderation-system

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nguyentranchung-laravel-moderation/health.svg)

```
[![Health](https://phpackages.com/badges/nguyentranchung-laravel-moderation/health.svg)](https://phpackages.com/packages/nguyentranchung-laravel-moderation)
```

###  Alternatives

[hootlex/laravel-moderation

A simple Content Moderation System for Laravel 5.\* that allows you to Approve or Reject resources like posts, comments, users, etc.

527122.8k](/packages/hootlex-laravel-moderation)[martbock/laravel-diceware

Diceware Passphrase Generator for Laravel

3264.7k](/packages/martbock-laravel-diceware)[orchestra/auth

Auth Component for Orchestra Platform

24108.5k3](/packages/orchestra-auth)[ingria/laravel-x509-auth

Laravel 5 Client Certificate auth middleware

375.6k](/packages/ingria-laravel-x509-auth)

PHPackages © 2026

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