All Projects → victorlap → Laravel Approvable

victorlap / Laravel Approvable

Licence: mit
Easily add an approval process to any laravel model.

Projects that are alternatives of or similar to Laravel Approvable

Laravel Graphql
GraphQL implementation with power of Laravel
Stars: ✭ 56 (-29.11%)
Mutual labels:  eloquent, laravel
Eloquent Approval
Approval process for Laravel Eloquent models
Stars: ✭ 79 (+0%)
Mutual labels:  eloquent, laravel
Xero Laravel
💸 Access the Xero accounting system using an Eloquent-like syntax
Stars: ✭ 58 (-26.58%)
Mutual labels:  eloquent, laravel
Requent
A GraphQL like interface to map a request to eloquent query with data transformation for Laravel.
Stars: ✭ 78 (-1.27%)
Mutual labels:  eloquent, laravel
Laravel Schedulable
Schedule and unschedule eloquent models elegantly without cron jobs
Stars: ✭ 78 (-1.27%)
Mutual labels:  eloquent, laravel
Freelancers Market
Laravel Project to help freelance websites clients and freelancers to find each other.
Stars: ✭ 39 (-50.63%)
Mutual labels:  eloquent, laravel
Eloquentfilter
An Eloquent Way To Filter Laravel Models And Their Relationships
Stars: ✭ 1,113 (+1308.86%)
Mutual labels:  eloquent, laravel
Gorose
GoRose(go orm), a mini database ORM for golang, which inspired by the famous php framwork laravle's eloquent. It will be friendly for php developer and python or ruby developer. Currently provides six major database drivers: mysql,sqlite3,postgres,oracle,mssql, Clickhouse.
Stars: ✭ 947 (+1098.73%)
Mutual labels:  eloquent, laravel
Eloquent Settings
Eloquent Settings allows you to bind key-value pairs to any Laravel Eloquent model. It supports even casting for boolean, float or integer types.
Stars: ✭ 71 (-10.13%)
Mutual labels:  eloquent, laravel
Laravel Optimistic Locking
Adds optimistic locking feature to eloquent models.
Stars: ✭ 71 (-10.13%)
Mutual labels:  eloquent, laravel
Lara Eye
Filter your Query\Builder using a structured query language
Stars: ✭ 39 (-50.63%)
Mutual labels:  eloquent, laravel
Laravel Ownership
Laravel Ownership simplify management of Eloquent model's owner.
Stars: ✭ 71 (-10.13%)
Mutual labels:  eloquent, laravel
Time Traveller
Time travel for your Laravel Models.
Stars: ✭ 36 (-54.43%)
Mutual labels:  eloquent, laravel
Laravel Tags
Add tags and taggable behaviour to your Laravel app
Stars: ✭ 1,026 (+1198.73%)
Mutual labels:  eloquent, laravel
Rememberable
Query caching for Laravel
Stars: ✭ 960 (+1115.19%)
Mutual labels:  eloquent, laravel
Laravel Reactions
Laravel reactions package for implementing reactions (eg: like, dislike, love, emotion, etc) on Eloquent models.
Stars: ✭ 58 (-26.58%)
Mutual labels:  eloquent, laravel
Improved Polymorphic Eloquent Builder
🔨 Improved Polymorphic Eloquent Builder
Stars: ✭ 12 (-84.81%)
Mutual labels:  eloquent, laravel
Eloquent Driver
A package that allows you to store Statamic entries in a database.
Stars: ✭ 28 (-64.56%)
Mutual labels:  eloquent, laravel
Watchable
Enable users to watch various models in your application.
Stars: ✭ 65 (-17.72%)
Mutual labels:  eloquent, laravel
Elasticquent
Maps Laravel Eloquent models to Elasticsearch types
Stars: ✭ 1,172 (+1383.54%)
Mutual labels:  eloquent, laravel

Laravel Approvable

Latest Version on Packagist Software License Build Status Coverage Status Quality Score StyleCI Total Downloads

Easily add an approval process to any laravel model.

Description

Laravel Approvable is a package which helps when you have certain models in your application that should be editable by users, but the fields that they edit need to be approved first.

Installation

Via Composer

$ composer require victorlap/laravel-approvable

You can publish the migration with:

php artisan vendor:publish --provider="Victorlap\Approvable\ApprovableServiceProvider" --tag="migrations"
php artisan migrate

Setup

Assume you have a Post model. Each visitor on your site can edit any post, but before you want to publish the change to your website, you want to approve it first. By adding the \Victorlap\Approvable\Approvable trait to your Post model, when a visitor makes a change, a change request gets stored in the database. These changes can then later be applied, or denied by administrators. The currentUserCanApprove method can be used to determine who is authorized to make a change.

use Illuminate\Database\Eloquent\Model;
use Victorlap\Approvable\Approvable;

// Minimal
class Post extends Model
{
    use Approvable;   
}

// Extended
class Post extends Model
{
    use Approvable;

    protected $approveOf = array();

    protected $dontApproveOf = array();
    
    protected function currentUserCanApprove()
    {
        return Auth::check();
    }
    
    protected function getSystemUserId()
    {
        return Auth::id();
    }
}

Usage

Making a change to a model by a user who can approve does not change.

$post->title = "Very Good Post";
$post->save(); // This still works!

Making a change by an unauthorized user works the same.

$post->title = "Very Good Post";
$post->save(); // Post remains with the old title in the database, however a change request is now also present.

You can retrieve a list of attributes that have pending changes by using

$post->getPendingApprovalAttributes();

Or check if a certain attribute has pending changes

$post->isPendingApproval('title');

Scopes have been defined to quickly see approvals in different states. For example if you wnat to show administrators a list with changes that can be accepted you can use the open scope. Other scopes are accepted, rejected and ofClass.

Approval::open()->get();
Approval::accepted()->get();
Approval::rejected()->get();
Approval::ofClass(Post::class)->get();

You can combine the scopes of course, or use them in combination with regular query builder methods

Approval::open()->ofClass(Post::class)->get();

Accepting and rejecting of approvals can be done using the accept and reject methods on the Approval.

$approvals = Post::find(1)->approvals()->open()->get();
$approvals->each->accept(); // or
$approvals->each->reject();

If you dont want a model to pass approval, you can use the withoutApproval() method.

// Now this post model is not checked for changes.
$post->withoutApproval()
      ->fill([
        'title' => 'A new title',
      ])
      ->save();

To re-enable the approval for this model instance, you can use the withApproval() method.

Limitations

Currently Approvable does not handle creation of models, PR's are welcome for this.

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

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