Skip to main content

Author plus one peer required before publishing a post.

Approval steps

Configure approval counts and optional rejection thresholds.

Step 1
Signer requirements
Rejection thresholdsOptional
Preview updates instantly as you tweak settings.
<?php

use Illuminate\Database\Eloquent\Model;
use OVAC\Guardrails\Concerns\Guardrail;
use OVAC\Guardrails\Services\Flow;

/**
 * Example model used in the Guardrails playground.
 */
class ExampleModel extends Model
{
    use Guardrail;

    /**
     * Guardrails should watch these attributes for approval.
     *
     * @return array<int, string> Attribute keys that require review before persisting.
     */
    public function guardrailAttributes(): array
    {
        return ['published'];
    }

    /**
     * Describe the Guardrails approval workflow for this model.
     *
     * @param  array<string, mixed>  $dirty  Pending attribute changes captured for approval.
     * @param  string  $event  Model lifecycle event (creating/updating/custom) that triggered capture.
     * @return array<int, array<string, mixed>> Normalized multi-step Guardrails definition.
     */
    public function guardrailApprovalFlow(array $dirty, string $event): array
    {
        return [
            Flow::make() // Start a new Guardrails flow
                ->includeInitiator(true, true)
                // Step 1 - Editorial Review
                ->permissions(['content.publish'])
                ->signedBy(2, 'Editorial Review')
                // Finalize flow definition
                ->build(),
        ];
    }
}