›
›
›
  1. docs
  2. ›
  3. byrcsc/laravel-approval
1.x
Browse documentationOpenClose

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Workflows and stages
  • Choosing the workflow
  • Approvers and resolvers
  • Requests and state
  • Conditional stages

Approval flow

  • Submitting for approval
  • Recording decisions
  • Attribute drafts
  • Returns and resubmission
  • Bulk decisions

Assignments and deadlines

  • Delegation and reassignment
  • SLAs and escalation

Reading and authorization

  • Eligibility and authorization
  • Queries and timelines
  • Events and listeners
  • Notifications
  • Notification content

Operations

  • Workflow definitions
  • Audit trail and evidence
  • Console commands
  • Testing
  • Troubleshooting

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Workflows and stages
  • Choosing the workflow
  • Approvers and resolvers
  • Requests and state
  • Conditional stages

Approval flow

  • Submitting for approval
  • Recording decisions
  • Attribute drafts
  • Returns and resubmission
  • Bulk decisions

Assignments and deadlines

  • Delegation and reassignment
  • SLAs and escalation

Reading and authorization

  • Eligibility and authorization
  • Queries and timelines
  • Events and listeners
  • Notifications
  • Notification content

Operations

  • Workflow definitions
  • Audit trail and evidence
  • Console commands
  • Testing
  • Troubleshooting

byrcsc/laravel-approval · 1.x

Quick start.

Create a workflow and approve a proposed model change in four steps.

This walkthrough holds a purchase order amount until a finance user approves it. It assumes Laravel Approval is installed.

1. Make the model approvable

Add the Approvable concern and name the workflow the model uses:

use ByRcsc\LaravelApproval\Concerns\Approvable;
use Illuminate\Database\Eloquent\Model;

class PurchaseOrder extends Model
{
    use Approvable;

    public function approvalWorkflow(): string
    {
        return 'purchase-order';
    }

    public function approvableAttributes(): array
    {
        return ['amount', 'supplier_id', 'notes'];
    }
}

approvalWorkflow() removes the need to pass the workflow slug during every submission. approvableAttributes() limits which proposed attributes a request may hold.

2. Create a workflow

Create one stage and assign the finance user:

use ByRcsc\LaravelApproval\Models\ApprovalWorkflow;

$workflow = ApprovalWorkflow::create([
    'name' => 'Purchase orders',
    'slug' => 'purchase-order',
]);

$stage = $workflow->stages()->create([
    'sequence' => 1,
    'name' => 'Finance',
    'required_approvals' => 1,
]);

$stage->approvers()->create([
    'approver_type' => $financeUser->getMorphClass(),
    'approver_id' => $financeUser->getKey(),
]);

This stage needs one approval. You can add more stages after the first flow is working.

For workflows stored in source control, see workflow definitions.

3. Submit a proposed change

Create the purchase order, then submit a higher amount for approval:

$order = PurchaseOrder::create([
    'supplier_id' => $supplier->id,
    'amount' => 4_000,
]);

$request = $order->submitForApproval(
    newAttributes: ['amount' => 10_000],
);

The purchase order still contains 4000. The proposed 10000 is stored on the approval request.

Omit newAttributes when the request should approve the existing record without changing its attributes.

4. Approve the request

Record the finance user's decision:

use ByRcsc\LaravelApproval\Facades\Approval;

Approval::approve(
    $request,
    $financeUser,
    'Within the quarterly budget',
);

The only stage is now complete. Laravel Approval marks the request as approved and applies the draft:

$request->fresh()->state; // RequestState::Approved
$order->fresh()->amount;  // 10000

Rejecting or returning a request requires a reason:

Approval::reject($request, $financeUser, 'Over budget');

Approval::returnForRevision(
    $request,
    $financeUser,
    'Attach the supplier quote',
);

What to read next

  • Workflows and stages to add stages, thresholds, and rejection rules.
  • Approvers and resolvers to assign roles, teams, or managers.
  • Attribute drafts to handle stale records and conflicts.
  • Queries and timelines to build approver inboxes and progress screens.
  • Eligibility and authorization to decide when action buttons should appear.
PreviousInstallation and setupNextWorkflows and stages
View source

On this page

  1. 1. Make the model approvable
  2. 2. Create a workflow
  3. 3. Submit a proposed change
  4. 4. Approve the request
  5. What to read next