Download the PHP package hootlex/laravel-moderation without Composer
On this page you can find all versions of the php package hootlex/laravel-moderation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hootlex/laravel-moderation
More information about hootlex/laravel-moderation
Files in hootlex/laravel-moderation
Package laravel-moderation
Short Description A simple Content Moderation System for Laravel 5.* that allows you to Approve or Reject resources like posts, comments, users, etc.
License MIT
Informations about the package laravel-moderation
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
- User creates a resource (a post, a comment or any Eloquent Model).
- The resource is pending and invisible in website (ex.
Post::all()
returns only approved posts). -
Moderator decides if the resource will be approved, rejected or postponed.
- Approved: Resource is now public and queryable.
- Rejected: Resource will be excluded from all queries. Rejected resources will be returned only if you scope a query to include them. (scope:
withRejected
) - Postponed: Resource will be excluded from all queries until Moderator decides to approve it.
- You application is clean.
Installation
First, install the package through Composer.
If you are using Laravel < 5.5, you need to add Hootlex\Moderation\ModerationServiceProvider to your config/app.php
providers array:
Lastly you publish the config file.
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.
Create a migration to add the new columns. (You can use custom names for the moderation columns)
Example Migration:
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:
or by referencing it's id
or by making a query.
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.
Query pending or rejected models.
Query ALL models
Model Status
To check the status of a model there are 3 helper methods which return a boolean value.
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:
status_column
represents the default column 'status' in the database.moderated_at_column
represents the default column 'moderated_at' in the database.moderated_by_column
represents the default column 'moderated_by' in the database.strict
represents Strict Moderation.
Model Configuration
Inside your Model you can define some variables to overwrite Global Settings.
To overwrite status
column define:
To overwrite moderated_at
column define:
To overwrite moderated_by
column define:
To enable or disable Strict Moderation: