PHP code example of aymanalhattami / laravel-approval

1. Go to this page and download the library: Download aymanalhattami/laravel-approval 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/ */

    

aymanalhattami / laravel-approval example snippets


use Approval\Traits\RequiresApproval;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use RequiresApproval;
}

/**
* Function that defines the rule of when an approval process
* should be actioned for this model.
*
* @param array $modifications
*
* @return boolean
*/
protected function mmediately without approval.
    return false;
}

/**
* Number of approvers this model ted.
*
* @var integer
*/
protected $approversRequired = 1;

/**
* Number of disapprovers this model this model should be updated
* automatically upon receiving the number
* of disapprovals.
*
* @var boolean
*/
protected $deleteWhenDisapproved = false;

/**
* Boolean to mark whether or not the approval model should be deleted
* automatically when the approval is approved wtih the 

use Approval\Traits\ApprovesChanges;
use Illuminate\Database\Eloquent\Model;

class Admin extends Model
{
    use ApprovesChanges;
}

use Approval\Traits\ApprovesChanges;
use Illuminate\Database\Eloquent\Model;

class Admin extends Model
{
    use ApprovesChanges;

    protected function authorizedToApprove(\Approval\Models\Modification $mod) : bool
    {
        // Return true to authorize approval, false to deny
        return true;
    }
}

use Approval\Traits\ApprovesChanges;
use Illuminate\Database\Eloquent\Model;

class Admin extends Model
{
    use ApprovesChanges;

    protected function authorizedToApprove(\Approval\Models\Modification $mod) : bool
    {
        // Return true to authorize approval, false to deny
        return true;
    }

    protected function authorizedToDisapprove(\Approval\Models\Modification $mod) : bool
    {
        // Return true to authorize disapproval, false to deny
        return true;
    }
}

$post = Post::find(1);
$post->modifications()->get();

$post = Post::find(1);
$post->modifications()->creations()->get();

$post = Post::find(1);
$post->modifications()->changed()->get();

$post = Post::find(1);
$post->modifications()->first()->modifier();

$active = Post::find(1)->modifications()->activeOnly()->get();
$inactive = Post::find(1)->modifications()->inactiveOnly()->get();
$any = Post::find(1)->modifications()->get();

$modification = Post::find(1)->modifications()->first();
$reason = "This is optional reason.";

$approver = Admin::first();
$approver->approve($modification, $reason);

$modification = Post::find(1)->modifications()->first();
$reason = "This is optional reason.";

$approver = Admin::first();
$approver->disapprove($modification, $reason);

$post         = Post::find(1);
$modification = $post->modifications()->first();
$approval     = $modification->approvals()->get();

$post         = Post::find(1);
$modification = $post->modifications()->first();
$approval     = $modification->approvals()->get();
$author       = $approval->approver();

$post         = Post::find(1);
$modification = $post->modifications()->first();
$approval     = $modification->approvals()->first();
$reason       = $approval->reason;

$post         = Post::find(1);
$modification = $post->modifications()->first();
$approval     = $modification->disapprovals()->get();

$post         = Post::find(1);
$modification = $post->modifications()->first();
$approval     = $modification->disapprovals()->get();
$author       = $approval->disapprover();

$post         = Post::find(1);
$modification = $post->modifications()->first();
$approval     = $modification->disapprovals()->first();
$reason       = $approval->reason;

$post         = Post::find(1);
$modification = $post->modifications()->first();
$remaining    = $modification->approversRemaining;

$post         = Post::find(1);
$modification = $post->modifications()->first();
$remaining    = $modification->disapproversRemaining;

$post         = Post::find(1);
$modification = $post->modifications()->first();
$modification->forceApprovalUpdate();