{"id":13396075,"url":"https://github.com/hootlex/laravel-moderation","last_synced_at":"2025-05-15T22:09:33.939Z","repository":{"id":3682920,"uuid":"50531739","full_name":"hootlex/laravel-moderation","owner":"hootlex","description":"A simple Content Moderation System for Laravel 5.* that allows you to Approve or Reject resources like posts, comments, users, etc.","archived":false,"fork":false,"pushed_at":"2022-03-08T03:42:08.000Z","size":55,"stargazers_count":527,"open_issues_count":19,"forks_count":68,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-05-15T22:08:53.370Z","etag":null,"topics":["eloquent","laravel","laravel-moderation","moderation"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hootlex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-27T19:22:00.000Z","updated_at":"2025-04-07T19:48:13.000Z","dependencies_parsed_at":"2022-08-06T14:15:17.868Z","dependency_job_id":null,"html_url":"https://github.com/hootlex/laravel-moderation","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hootlex%2Flaravel-moderation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hootlex%2Flaravel-moderation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hootlex%2Flaravel-moderation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hootlex%2Flaravel-moderation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hootlex","download_url":"https://codeload.github.com/hootlex/laravel-moderation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254430330,"owners_count":22069909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eloquent","laravel","laravel-moderation","moderation"],"created_at":"2024-07-30T18:00:39.102Z","updated_at":"2025-05-15T22:09:30.565Z","avatar_url":"https://github.com/hootlex.png","language":"PHP","funding_links":[],"categories":["Popular Packages"],"sub_categories":[],"readme":"# Laravel Moderation [![Build Status](https://travis-ci.org/hootlex/laravel-moderation.svg?branch=v1.0.11)](https://travis-ci.org/hootlex/laravel-moderation) [![Version](https://img.shields.io/packagist/v/hootlex/laravel-moderation.svg?style=flat)](https://packagist.org/packages/hootlex/laravel-moderation)  [![Total Downloads](https://img.shields.io/packagist/dt/hootlex/laravel-moderation.svg?style=flat)](https://packagist.org/packages/hootlex/laravel-moderation) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](LICENSE)\nA simple Moderation System for Laravel 5.* that allows you to Approve or Reject resources like posts, comments, users, etc.\n\nKeep your application pure by preventing offensive, irrelevant, or insulting content.\n\n## Possible Use Case\n\n1. User creates a resource (a post, a comment or any Eloquent Model).\n2. The resource is pending and invisible in website (ex. `Post::all()` returns only approved posts).\n3. Moderator decides if the resource will be approved, rejected or postponed.\n\n  1. **Approved**: Resource is now public and queryable.\n  2. **Rejected**: Resource will be excluded from all queries. Rejected resources will be returned only if you scope a query to include them. (scope: `withRejected`)\n  3. **Postponed**: Resource will be excluded from all queries until Moderator decides to approve it.\n\n4. You application is clean.\n\n## Installation\n\nFirst, install the package through Composer.\n\n```php\ncomposer require hootlex/laravel-moderation\n```\n\nIf you are using Laravel \u003c 5.5, you need to add Hootlex\\Moderation\\ModerationServiceProvider to your `config/app.php` providers array:\n```php\n'providers' =\u003e [\n    ...\n    Hootlex\\Moderation\\ModerationServiceProvider::class,\n    ...\n];\n```\nLastly you publish the config file.\n\n```\nphp artisan vendor:publish --provider=\"Hootlex\\Moderation\\ModerationServiceProvider\" --tag=config\n```\n\n\n## Prepare Model\n\nTo 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.\n```php\nuse Hootlex\\Moderation\\Moderatable;\nclass Post extends Model\n{\n    use Moderatable;\n    ...\n}\n```\n\nCreate a migration to add the new columns. [(You can use custom names for the moderation columns)](#configuration)\n\nExample Migration:\n```php\nclass AddModerationColumnsToPostsTable extends Migration\n{\n    /**\n     * Run the migrations.\n     *\n     * @return void\n     */\n    public function up()\n    {\n        Schema::table('posts', function (Blueprint $table) {\n            $table-\u003esmallInteger('status')-\u003edefault(0);\n            $table-\u003edateTime('moderated_at')-\u003enullable();\n            //To track who moderated the Model, add 'moderated_by' and set the column name in the config file.\n            //$table-\u003einteger('moderated_by')-\u003enullable()-\u003eunsigned();\n        });\n    }\n\n    /**\n     * Reverse the migrations.\n     *\n     * @return void\n     */\n    public function down()\n    {\n        Schema::table('posts', function(Blueprint $table)\n        {\n            $table-\u003edropColumn('status');\n            $table-\u003edropColumn('moderated_at');\n            //$table-\u003edropColumn('moderated_by');\n        });\n    }\n}\n```\n\n**You are ready to go!**\n\n## Usage\n\u003e **Note:** In next examples I will use Post model to demonstrate how the query builder works. You can Moderate any Eloquent Model, even User. \n\n### Moderate Models\nYou can moderate a model Instance:\n```php\n$post-\u003emarkApproved();\n\n$post-\u003emarkRejected();\n\n$post-\u003emarkPostponed();\n\n$post-\u003emarkPending();\n```\n\nor by referencing it's id\n```php\nPost::approve($post-\u003eid);\n\nPost::reject($post-\u003eid);\n\nPost::postpone($post-\u003eid);\n```\n\nor by making a query.\n```php\nPost::where('title', 'Horse')-\u003eapprove();\n\nPost::where('title', 'Horse')-\u003ereject();\n\nPost::where('title', 'Horse')-\u003epostpone();\n```\n\n### Query Models\nBy default only Approved models will be returned on queries. To change this behavior check the [configuration](#configuration).\n\n##### To query the Approved Posts, run your queries as always.\n```php\n//it will return all Approved Posts (strict mode)\nPost::all();\n\n// when not in strict mode\nPost::approved()-\u003eget();\n\n//it will return Approved Posts where title is Horse\nPost::where('title', 'Horse')-\u003eget();\n\n```\n##### Query pending or rejected models.\n```php\n//it will return all Pending Posts\nPost::pending()-\u003eget();\n\n//it will return all Rejected Posts\nPost::rejected()-\u003eget();\n\n//it will return all Postponed Posts\nPost::postponed()-\u003eget();\n\n//it will return Approved and Pending Posts\nPost::withPending()-\u003eget();\n\n//it will return Approved and Rejected Posts\nPost::withRejected()-\u003eget();\n\n//it will return Approved and Postponed Posts\nPost::withPostponed()-\u003eget();\n```\n##### Query ALL models\n```php\n//it will return all Posts\nPost::withAnyStatus()-\u003eget();\n\n//it will return all Posts where title is Horse\nPost::withAnyStatus()-\u003ewhere('title', 'Horse')-\u003eget();\n```\n\n### Model Status\nTo check the status of a model there are 3 helper methods which return a boolean value.\n```php\n//check if a model is pending\n$post-\u003eisPending();\n\n//check if a model is approved\n$post-\u003eisApproved();\n\n//check if a model is rejected\n$post-\u003eisRejected();\n\n//check if a model is rejected\n$post-\u003eisPostponed();\n```\n\n## Strict Moderation\nStrict 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).\n\n## Configuration\n\n### Global Configuration\nTo configuration Moderation package globally you have to edit `config/moderation.php`.\nInside `moderation.php` you can configure the following:\n\n1. `status_column` represents the default column 'status' in the database. \n2. `moderated_at_column` represents the default column 'moderated_at' in the database.\n2. `moderated_by_column` represents the default column 'moderated_by' in the database.\n3. `strict` represents [*Strict Moderation*](#strict-moderation).\n\n### Model Configuration\nInside your Model you can define some variables to overwrite **Global Settings**.\n\nTo overwrite `status` column define:\n```php\nconst MODERATION_STATUS = 'moderation_status';\n```\n\nTo overwrite `moderated_at` column define:\n```php\nconst MODERATED_AT = 'mod_at';\n```\n\nTo overwrite `moderated_by` column define:\n```php\nconst MODERATED_BY = 'mod_by';\n```\n\nTo enable or disable [Strict Moderation](#strict-moderation):\n```php\npublic static $strictModeration = true;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhootlex%2Flaravel-moderation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhootlex%2Flaravel-moderation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhootlex%2Flaravel-moderation/lists"}