roundly-consulting / workflows-for-laravel
Durable, versioned workflows for Laravel: JSON graphs run step by step on queues, with triggers, declarative conditions, approvals, durable waits, business-time delays, escalations, retries, dry-runs and templates.
Package info
github.com/roundly-consulting/workflows-for-laravel
pkg:composer/roundly-consulting/workflows-for-laravel
Fund package maintenance!
Requires
- php: ^8.4
- illuminate/auth: ^13.0
- illuminate/bus: ^13.0
- illuminate/cache: ^13.0
- illuminate/console: ^13.0
- illuminate/container: ^13.0
- illuminate/contracts: ^13.0
- illuminate/database: ^13.0
- illuminate/events: ^13.0
- illuminate/filesystem: ^13.0
- illuminate/http: ^13.0
- illuminate/pagination: ^13.0
- illuminate/queue: ^13.0
- illuminate/routing: ^13.0
- illuminate/support: ^13.0
- illuminate/translation: ^13.0
- illuminate/validation: ^13.0
- roundly-consulting/crypto-for-laravel: ^2.0
- roundly-consulting/enums-for-laravel: ^2.0
- roundly-consulting/package-toolkit-for-laravel: ^2.1
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.18
- nunomaduro/collision: ^8.5
- orchestra/testbench: ^11.0
- pestphp/pest: ^5.0
- pestphp/pest-plugin-arch: ^5.0
- pestphp/pest-plugin-laravel: ^5.0
- phpstan/extension-installer: ^1.4
- roundly-consulting/approvals-for-laravel: ^2.1
- roundly-consulting/forms-for-laravel: ^2.0
- roundly-consulting/lifecycle-for-laravel: ^2.0
- roundly-consulting/notifications-for-laravel: ^1.1
- roundly-consulting/opening-hours-for-laravel: ^2.1
- roundly-consulting/sentinel-for-laravel: ^2.0
- roundly-consulting/teams-for-laravel: ^2.0
- roundly-consulting/testing-for-laravel: ^2.1
- roundly-consulting/webhooks-for-laravel: ^1.0
Suggests
- roundly-consulting/approvals-for-laravel: Approval steps: rules, stages, delegation, expiry; outcomes approved / rejected / expired.
- roundly-consulting/forms-for-laravel: Input forms for manual triggers.
- roundly-consulting/lifecycle-for-laravel: Transition steps that request a lifecycle transition; the guard decides.
- roundly-consulting/notifications-for-laravel: Notify steps and notify escalations.
- roundly-consulting/opening-hours-for-laravel: Business-hours calendars for delays and escalations ("2 business days").
- roundly-consulting/sentinel-for-laravel: RFC 9421 signature checks on the inbound webhook route.
- roundly-consulting/teams-for-laravel: Team owners: context restored in every queued step, team roles as approvers.
- roundly-consulting/webhooks-for-laravel: Signed inbound webhooks that start workflows (the `workflows` handler), and outbound `webhook` steps.
Provides
None
Conflicts
Replaces
None
README
Workflows for Laravel
Versioned workflows stored as JSON graphs and run step by step on your queues: triggers, conditions, approvals, durable waits, business-time delays, escalations, retries, dry runs and templates. Your users edit a workflow in a builder; the engine runs each published version exactly as it was published.
Installation
Requires PHP 8.4, Laravel 13, and a MySQL or PostgreSQL database.
composer require roundly-consulting/workflows-for-laravel roundly-consulting/approvals-for-laravel
php artisan workflows:install
php artisan vendor:publish --tag="approvals-migrations"
php artisan migrate
Approvals powers the approval step in the example below; leave it out if you don't need approvals.
Steps run on your queue, and a step may run for up to 570 seconds, so raise the connection's
retry_after above that (DB_QUEUE_RETRY_AFTER=600 for Laravel's default database queue) —
php artisan workflows:doctor checks it.
Delays, timeouts, retries, escalations and schedules wake on the scheduler, so add one line:
// routes/console.php use Illuminate\Support\Facades\Schedule; Schedule::command('workflows:wake')->everyMinute()->withoutOverlapping(10)->onOneServer();
Usage
use RoundlyConsulting\Workflows\Facades\Workflows; use RoundlyConsulting\Workflows\Graph\Build\{Party, Trigger, When}; // Once, in a service provider: what a purchase request looks like to the engine. Workflows::subjects()->register( Workflows::subject('purchase_request', PurchaseRequest::class) ->label('Purchase request') ->ownedBy('team') ->field('amount', 'decimal', 'Amount') ->field('requester', 'party', 'Requester') ->field('approver', 'party', 'Approver'), ); // The workflow itself is data: a JSON graph your users edit in a builder — or written in PHP. $definition = Workflows::definitions()->create(key: 'purchase-approval', name: 'Purchase approval', subjectType: 'purchase_request', owner: $team); Workflows::definition('purchase-approval', $team)->edit(Workflows::graph() // or ->edit(json_decode($json, true)) ->trigger('start', Trigger::manual()) ->condition('check', When::field('subject.amount')->gt('500')) ->approval('approve', approvers: [Party::field('subject.approver')]) ->end('done') ->connect('start', 'check') ->connect('check', 'approve', on: 'true') ->connect('check', 'done', on: 'false') ->connect('approve', 'done', on: ['approved', 'rejected', 'expired'])); Workflows::definition('purchase-approval', $team)->publish(by: $admin); // Start it (this graph's trigger is `manual`) — with an `event` trigger the app event starts it instead. $result = Workflows::start('purchase-approval', subject: $request, owner: $team) ->by($request->requester) ->idempotencyKey("submit:{$request->id}") ->dispatch(); $result->instance->status; // InstanceStatus::Running — a queue worker runs it on to the approval step, where it waits
Approval, notify, transition, opening-hours and form steps light up when the matching Roundly package is installed; everything else works on its own.
Documentation
The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/workflows-for-laravel
Release notes are in CHANGELOG.md. To contribute, see the contributing guide.
Support our work
This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.
License
The MIT License (MIT). See LICENSE.md.