百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
L

laravel-moderation

> 后端框架
开源

一个简单的 Laravel 5.* 内容审核系统,可让您批准或拒绝诸如帖子、评论、用户等资源。

529 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个简单的 Laravel 5.* 内容审核系统,可让您批准或拒绝诸如帖子、评论、用户等资源。

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

  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

First, install the package through Composer.

php
composer require hootlex/laravel-moderation

If you are using Laravel [ ... Hootlex\Moderation\ModerationServiceProvider::class, ... ];

Lastly you publish the config file.

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


## 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.
```php
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)

Example Migration:

php
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

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

You can moderate a model Instance:

php
$post->markApproved();

$post->markRejected();

$post->markPostponed();

$post->markPending();

or by referencing it's id

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

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

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

or by making a query.

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

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

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

Query Models

By default only Approved models will be returned on queries. To change this behavior check the configuration.

To query the Approved Posts, run your queries as always.
php
//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.
php
//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
php
//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

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

php
//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();

…

php
const MODERATION_STATUS = 'moderation_status';

To overwrite moderated_at column define:

php
const MODERATED_AT = 'mod_at';

To overwrite moderated_by column define:

php
const MODERATED_BY = 'mod_by';

To enable or disable Strict Moderation:

php
public static $strictModeration = true;

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPeloquentlaravellaravel-moderationmoderation

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架