Skip to content

Processable ​

Namespace: Unusualify\Modularous\Entities\Traits\Processable

Single-process workflow: models go through a preparing → waiting_for_confirmation → confirmed / rejected lifecycle. Uses HasFileponds (for evidence file uploads) and ProcessableScopes for query filtering.


Boot Behavior ​

EventAction
createdCreates an initial Process record with status ProcessStatus::PREPARING
savedIf processable_status is set, calls setProcessStatus and touches the model

Relationships ​

php
public function process(): MorphOne                      // → active Process record
public function processHistories(): HasManyThrough       // → ProcessHistory through Process
public function processHistory(): HasOneThrough          // → Latest ProcessHistory through Process

Computed Attributes ​

AttributeTypeDescription
has_process_historybooltrue if at least one ProcessHistory record exists
process_history_statusstring|nullStatus of the latest ProcessHistory
process_history_reasonstring|nullReason from the latest ProcessHistory

Methods ​

MethodSignatureDescription
setProcessStatus(string $status, ?string $reason = null): voidUpserts the Process record and creates a ProcessHistory entry
sendForConfirmation(): voidTransitions to WAITING_FOR_CONFIRMATION
confirm(): voidTransitions to CONFIRMED
reject(string $reason): voidTransitions to REJECTED with a reason
isProcessStatus(ProcessStatus $status): boolChecks if current status matches

Scopes ​

Provided by ProcessableScopes:

ScopeDescription
scopePreparing()Models with preparing status
scopeWaitingForConfirmation()Models pending review
scopeConfirmed()Models with confirmed process
scopeRejected()Models with rejected process

Usage ​

php
use Unusualify\Modularous\Entities\Traits\Processable;

class Application extends Model
{
    use Processable;
}

// Workflow transitions
$application->sendForConfirmation();
$application->confirm();
$application->reject('Missing required documents');

// Check status
$application->isProcessStatus(ProcessStatus::CONFIRMED); // true
$application->process_history_status;

// Query
Application::waitingForConfirmation()->get();
Application::confirmed()->latest()->get();