1. Go to this page and download the library: Download cjmellor/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/ */
// Set a custom state
$approval->setState('in_review');
// Check the current state
$currentState = $approval->getState();
// Query approvals with a specific state
$inReviewApprovals = Approval::whereState('in_review')->get();
// The standard scopes still work for the default states
$pendingApprovals = Approval::pending()->get();
Approval::first()->rollback();
Approval::first()->rollback(bypass: false); // default is true
Approval::first()->rollback(fn () => true);
// ModelRolledBackEvent::class
public Model $approval,
public Authenticatable|null $user,
// Set expiration in hours (most common)
Approval::find(1)->expiresIn(hours: 24);
// Set expiration in minutes
Approval::find(1)->expiresIn(minutes: 30);
// Set expiration in days
Approval::find(1)->expiresIn(days: 7);
// Set specific expiration datetime
Approval::find(1)->expiresIn(datetime: now()->addWeek());
// Automatically reject when expired
Approval::find(1)->expiresIn(hours: 48)->thenReject();
// Automatically postpone (set to pending) when expired
Approval::find(1)->expiresIn(hours: 48)->thenPostpone();
// Use a custom action through event listeners
Approval::find(1)->expiresIn(hours: 48)->thenDo(function($approval) {
// This callback is for documentation only
// Implement an event listener for ApprovalExpired event
});
// In App\Console\Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('approval:process-expired')->everyMinute();
}
// Get all expired approvals
Approval::expired()->get();
// Get all non-expired approvals (including those with no expiration)
Approval::notExpired()->get();
// Get all approvals that have an expiration set
Approval::hasExpiration()->get();
// Check if a specific approval is expired
$approval->isExpired();