All packages
Requests for Laravel
Multi-stage pipelines
Define a sequential pipeline with stages(); each stage opens only once the previous one clears:
use RoundlyConsulting\Approvals\DataTransferObjects\StageDefinition;
use RoundlyConsulting\Approvals\Enums\ApprovalRule;
$request = Requests::make()
->title('Payout')
->stages([
new StageDefinition([$manager], ApprovalRule::Unanimous, name: 'manager'),
new StageDefinition([$finance], ApprovalRule::Unanimous, name: 'finance'),
new StageDefinition([$director], ApprovalRule::Unanimous, name: 'director'),
])
->create();
$request->currentStage()?->name; // 'manager'Approvals move the request through the stages; the request flips to Approved when the last stage clears:
Requests::approve($request, $manager);
$request->currentStage()?->name; // 'finance'
Requests::approve($request, $finance);
$request->currentStage()?->name; // 'director'
Requests::approve($request, $director);
$request->fresh()->status; // Status::ApprovedStageDefinition
Each stage has its own approvers, rule, quorum and name:
new StageDefinition(
approvers: [$a, $b, $c], // list<Model>
rule: ApprovalRule::Quorum, // defaults to ApprovalRule::Unanimous
quorum: 2, // ?int — for quorum / weighted stages
name: 'board', // ?string — shown by currentStage()->name
);Rejections inside a pipeline
By default a rejection in any stage rejects the whole request. Call rejectOnStageRejection(false) to skip the rejected stage and continue:
$request = Requests::make()
->rejectOnStageRejection(false)
->stages([
new StageDefinition([$manager], name: 'manager'),
new StageDefinition([$finance], name: 'finance'),
])
->create();
// The first stage rejects, but the pipeline carries on to the next stage.
Requests::reject($request, $manager, reason: 'Skip me');
$request->fresh()->status; // Status::New
$request->currentStage()?->name; // 'finance'Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.