All Projects → hootlex → Laravel Moderation

hootlex / Laravel Moderation

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

Projects that are alternatives of or similar to Laravel Moderation

Laravel Eloquent Join
This package introduces the join magic for eloquent models and relations.
Stars: ✭ 270 (-44.56%)
Mutual labels:  eloquent, laravel
Laravel Bookings
Rinvex Bookable is a generic resource booking system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
Stars: ✭ 309 (-36.55%)
Mutual labels:  eloquent, laravel
Laravel Translator
An Eloquent translator for Laravel
Stars: ✭ 275 (-43.53%)
Mutual labels:  eloquent, laravel
Quicksand
Easily schedule regular cleanup of old soft-deleted Eloquent data.
Stars: ✭ 259 (-46.82%)
Mutual labels:  eloquent, laravel
Laravel Eloquent Uuid
A simple drop-in solution for providing UUID support for the IDs of your Eloquent models.
Stars: ✭ 388 (-20.33%)
Mutual labels:  eloquent, laravel
Eloquent Builder
Provides an advanced filter for Laravel or Lumen model.
Stars: ✭ 264 (-45.79%)
Mutual labels:  eloquent, laravel
Laravel Attributes
Rinvex Attributable is a robust, intelligent, and integrated Entity-Attribute-Value model (EAV) implementation for Laravel Eloquent, with powerful underlying for managing entity attributes implicitly as relations with ease. It utilizes the power of Laravel Eloquent, with smooth and seamless integration.
Stars: ✭ 304 (-37.58%)
Mutual labels:  eloquent, laravel
Laravel Jit Loader
Stars: ✭ 210 (-56.88%)
Mutual labels:  eloquent, laravel
Elasticsearch
The missing elasticsearch ORM for Laravel, Lumen and Native php applications
Stars: ✭ 375 (-23%)
Mutual labels:  eloquent, laravel
Plans
Laravel Plans is a package for SaaS apps that need management over plans, features, subscriptions, events for plans or limited, countable features.
Stars: ✭ 326 (-33.06%)
Mutual labels:  eloquent, laravel
Bouncer
Eloquent roles and abilities.
Stars: ✭ 2,763 (+467.35%)
Mutual labels:  eloquent, laravel
Laravel Wallet
Easy work with virtual wallet
Stars: ✭ 401 (-17.66%)
Mutual labels:  eloquent, laravel
Laravel Database Encryption
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Stars: ✭ 238 (-51.13%)
Mutual labels:  eloquent, laravel
Laravel Medialibrary
Associate files with Eloquent models
Stars: ✭ 4,743 (+873.92%)
Mutual labels:  eloquent, laravel
Laravel Shareable Models
Create shareable links from your eloquent models.
Stars: ✭ 225 (-53.8%)
Mutual labels:  eloquent, laravel
Decoy
A Laravel model-based CMS
Stars: ✭ 303 (-37.78%)
Mutual labels:  eloquent, laravel
Laravel Computed Properties
Make your accessors smarter
Stars: ✭ 197 (-59.55%)
Mutual labels:  eloquent, laravel
Blogetc
Easily add a full Laravel blog (with built in admin panel and public views) to your laravel project with this simple package.
Stars: ✭ 198 (-59.34%)
Mutual labels:  eloquent, laravel
Corcel
Use WordPress backend with Laravel or any PHP application
Stars: ✭ 3,504 (+619.51%)
Mutual labels:  eloquent, laravel
Laravel Model Cleanup
Clean up unneeded records
Stars: ✭ 388 (-20.33%)
Mutual labels:  eloquent, laravel

Laravel Moderation Build Status Version Total Downloads Software License

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.

composer require hootlex/laravel-moderation

If you are using Laravel < 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

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)

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

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:

$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

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

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

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.

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:

public static $strictModeration = true;
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].