roundly-consulting / approvals-for-laravel
Record polymorphic approvals between Eloquent models for Laravel.
Package info
github.com/roundly-consulting/approvals-for-laravel
pkg:composer/roundly-consulting/approvals-for-laravel
Fund package maintenance!
Requires
- php: ^8.4
- illuminate/contracts: ^12.0|^13.0
- roundly-consulting/enums-for-laravel: ^1.0
- roundly-consulting/package-toolkit-for-laravel: ^1.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.18
- nunomaduro/collision: ^8.0
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^4.4
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.1
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- roundly-consulting/testing-for-laravel: ^1.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Approvals for Laravel
Model approvals, rejections, and multi-approver sign-off between Eloquent models. Any model can decide on any other, and a subject can open a request that resolves by unanimous, quorum, any-one or weighted rules — as staged pipelines, with delegation, expiry and an event for every transition.
Installation
Requires PHP 8.4 and Laravel 12 or 13.
composer require roundly-consulting/approvals-for-laravel
php artisan vendor:publish --tag="approvals-migrations"
php artisan migrate
If your models have UUID/ULID keys, set APPROVALS_KEY_TYPE=uuid (or ulid) before migrating.
Usage
Give the deciding model and the decided-on model their traits:
use Illuminate\Database\Eloquent\Model; use RoundlyConsulting\Approvals\Traits\GivesApprovals; use RoundlyConsulting\Approvals\Traits\HasApprovals; use RoundlyConsulting\Approvals\Traits\RequiresApproval; class User extends Model { use GivesApprovals; } class Invoice extends Model { use HasApprovals; use RequiresApproval; }
Then open a request that needs two of three named approvers — it resolves as their decisions come in:
use RoundlyConsulting\Approvals\Facades\Approvals; Approvals::request($invoice)->from([$lead, $qa, $pm])->quorum(2)->open(); Approvals::for($invoice)->as($lead)->approve(); Approvals::status($invoice); // ApprovalStatus::Pending — 1 of 2 Approvals::for($invoice)->as($intern)->approve(); // throws UnauthorizedApprovalException: not named Approvals::for($invoice)->as($qa)->because('Totals check out')->approve(); Approvals::status($invoice); // ApprovalStatus::Approved $invoice->isApproved(); // true
Documentation
The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/approvals-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). Please see LICENSE for more information.