PHP code example of victorlap / laravel-approvable

1. Go to this page and download the library: Download victorlap/laravel-approvable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

victorlap / laravel-approvable example snippets


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();
    }
}

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

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

$post->getPendingApprovalAttributes();

$post->isPendingApproval('title');

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

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

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

// Now this post model is not checked for changes.
$post->withoutApproval()
      ->fill([
        'title' => 'A new title',
      ])
      ->save();
bash
php artisan vendor:publish --provider="Victorlap\Approvable\ApprovableServiceProvider" --tag="migrations"
php artisan migrate