PHP code example of apurba-labs / laravel-approval-engine
1. Go to this page and download the library: Download apurba-labs/laravel-approval-engine 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/ */
apurba-labs / laravel-approval-engine example snippets
class RequisitionModule extends BaseWorkflowModule
{
public function model(): string
{
return \App\Models\Requisition::class;
}
/**
* Validate records before they enter a batch.
* Useful for checking data integrity or custom business rules.
*/
public function validate(array $data): void
{
// Default: No validation public function statusColumn(): string
{
return 'status';
}
/**
* Default priorities: check for 'user', then 'creator'.
* Individual modules can override this.
*/
public function ownerRelations(): array
{
return ['user', 'creator'];
}
/**
* Allow developers to add extra relations (like 'items' or 'department').
*/
protected function customRelations(): array
{
return [];
}
public function selectColumns(): array
{
return [
'id',
'user_id',
'reference_id',
'stage',
'stage_status',
'status',
'approved_at',
];
}
public function displayColumns(): array
{
return [
'reference_id' => 'Reference',
'user.name' => 'Requested By',
];
}
public function relationModels(): array
{
return [
'user' => \ApurbaLabs\ApprovalEngine\Tests\Support\Models\User::class,
//'admin' => \App\Models\Admin::class,
];
}
}
bash
php artisan approval:demo
mermaid
graph TD
A[Batch Sent] --> B[Wait]
B --> C{Approved?}
C -- No --> D[Reminder]
D --> E{Still Pending?}
E -- Yes --> F[Escalate]