A purchase approval flow in Filament: route by amount, send back, approve
Liam in sales wants six standing desks for his team, 1,500,000 in total. Company rules say that his manager approves every purchase, the department director also approves anything over a million, finance gives an opinion, and purchasing is told. Today this happens by email: Liam writes to his manager, the manager forwards it to the director, someone forgets to copy finance, and three weeks later nobody knows where the request is.
A status column and a "Approve" button on the record cannot carry this. Who approves depends on the amount and on who Liam's manager is today. A manager may send it back with a question. And when the request comes back, the approvers want to know what changed.
This article follows one purchase request through the Warp Flow demo: the route worked out from the amount and the org chart, a return with a reason, a resubmission and an approval. All pictures are from the live demo. The demo uses yen, hence the large numbers.
The scene: a purchase request
Liam fills in an ordinary Filament form: the item, the category, the vendor, the quantity and the unit price.
Step 1: make the model approvable
Register the plugin with the models that can be approved:
use Qalainau\FilamentWarpFlow\FilamentWarpFlowPlugin;
->plugin(
FilamentWarpFlowPlugin::make()
->models([PurchaseRequest::class])
->canManage(fn (User $user) => $user->is_admin),
)
The model implements Approvable, uses HasApprovals, and declares the fields a flow may branch on:
use Qalainau\FilamentWarpFlow\ConditionField;
use Qalainau\FilamentWarpFlow\Concerns\HasApprovals;
use Qalainau\FilamentWarpFlow\Contracts\Approvable;
class PurchaseRequest extends Model implements Approvable
{
use HasApprovals;
public static function approvalConditionFields(): array
{
return [
ConditionField::number('amount', 'Amount'),
ConditionField::select('category', 'Category', PurchaseCategory::class),
];
}
}
And the edit page gets the approval actions. Each one only shows when the current user can use it right now:
use Qalainau\FilamentWarpFlow\Actions\ApprovalActions;
protected function getHeaderActions(): array
{
return [...ApprovalActions::make(), DeleteAction::make()];
}
The route itself is not code. An admin builds it in the panel's flow editor and presses Publish. The demo's purchase flow is: the applicant's manager, then a branch on the amount (over 5,000,000: director and president; over 1,000,000: director), an IT check for software, a finance review as a consultation, and purchasing for information.
Approvers are found relative to the applicant: their manager, the head of their department. When someone changes teams, the flow does not need to change.
Step 2: see the route before sending
"Submit for approval" shows exactly who will get the request, in which order, before anything is sent. 1,500,000 is over a million, so the department director is on it.
The route is fixed when the request is sent. Publishing a new version of the flow later does not change requests already under way.
A request is made from the record as saved. If the form has unsaved changes, the dialog asks to save first, so nobody approves numbers that are not in the database.
Step 3: the manager sends it back
Alex, Liam's manager, finds the request in the approval inbox. The request page shows the summary, the route and a row of approval stamps. The dashed blue circle is whose turn it is.
Alex wants a second quote before saying yes, so they press "Return". The request can go back to Liam or to an earlier approval step. A reason is required, and it stays in the request's thread.
Liam sees the request as Returned, with an orange "Returned" stamp in Alex's box, and buttons to resubmit or withdraw it.
Step 4: resubmit and approve
Liam resubmits with a comment. By default the request picks up at the step that returned it, so Alex sees it again without the request starting over. If the change alters the route before that step (a higher amount that adds a director), it starts from the first step.
Alex approves.
That last line matters. When a returned request comes back with changes, the request page shows them with the old value struck through ("480,000 → 398,000"), and the approval email says "Changed: Amount 480,000 → 398,000". Approvers do not have to compare by memory.
Other scenes
- Expense claims: travel over a set amount also goes to the director.
- Proposals and contracts: branch on the kind of contract or the department of the applicant.
- Leave requests: approved by themselves when the manager does not answer in time (due times and escalation).
- Requests with no model at all: a business trip request built from a request form in the panel, with no code.
The four step types cover most company rules: Approval (approve, return or reject), Consultation (agree or disagree; a disagreement does not stop the request), For information (people mark it as read) and Post-review (after the final approval).
Limits worth knowing
- Conditions can only use the fields the model declares in
approvalConditionFields()and the applicant's department and position. No free-form expressions. - Unsaved edits are not part of a request.
- After a rejection or a withdrawal, the record is submitted again as a new request.
- In the demo, everyone sees "Reassign" so you can try it. In your app, only people allowed to manage flows reassign steps.
Try it
Open the purchase requests in the demo. Use "Acting as" in the top bar to become the applicant, create a request over 1,000,000 and press "Submit for approval". Then switch to the manager and return or approve it from the approval inbox. No sign-up, and the data is reset every hour.