v1.0.0 · MIT License

Lifecycle rules for
Laravel Filament

Tenant-scoped automation engine — fire actions when members hit age milestones, tenure, inactivity, or spend thresholds. Build rules in the UI, evaluate on a schedule.

PHP 8.2+ Laravel 11+ Filament 5 MIT License

Everything you need

All the tools to build powerful lifecycle automations without writing custom cron jobs.

Preset Triggers

Five built-in trigger types: age milestones, tenure, inactivity, metric thresholds, and custom field matching — zero boilerplate.

Visual Conditions

Add AND conditions on any attribute/operator/value pair to filter subjects after the preset fires — all configurable in the Filament UI.

5 Built-in Actions

Update member meta, merge tenant settings, notify admins, create reminders, or dispatch Laravel events — extensible via host callbacks.

Idempotency

The rule_execution_logs table ensures rules fire at most once per subject, even if evaluation runs multiple times.

Filament UI

Full CRUD resource inside your existing Filament panel. Build, edit, enable, and audit rules without touching the database directly.

Login Evaluation

Optionally evaluate rules on member login for real-time trigger checks — useful for birthday greetings and inactivity reset triggers.

How it works

Up and running in four steps.

1

Install

Require via Composer, publish the config and migrations, then run migrate.

$ composer require spiggle/rules-engine
$ php artisan vendor:publish --tag=rules-engine-config
$ php artisan vendor:publish --tag=rules-engine-migrations
$ php artisan migrate
2

Register the plugin

Add the plugin to your Filament panel provider.

use Spiggle\RulesEngine\Filament\RulesEnginePlugin;

$panel->plugin(RulesEnginePlugin::make());
3

Configure host resolvers

Wire up your subject_model, scope_model, resolvers, and action callbacks in config/rules-engine.php.

4

Create rules & schedule

Build rules in the Filament UI and schedule evaluation.

Schedule::call(function () {
  app(RuleEvaluator::class)
    ->evaluateAllActiveRules('scheduled');
})->dailyAt('01:15');

Sample rule seed

// database/seeders/SampleRuleSeeder.php

use Spiggle\RulesEngine\Models\Rule;

Rule::create([
  'name'         => 'Happy 18th Birthday',
  'preset_type'  => 'age_milestone',
  'preset_params' => [
    'dob_attribute' => 'date_of_birth',
    'age'           => 18,
  ],
  'conditions'  => [],
  'actions'     => [
    [
      'type'    => 'notify_scope_admins',
      'payload' => [
        'message' => 'Member turns 18 today',
      ],
    ],
    [
      'type'    => 'set_member_meta',
      'payload' => [
        'key'   => 'adult_milestone_reached',
        'value' => true,
      ],
    ],
  ],
  'is_active'    => true,
  'scope_id'     => null, // null = all scopes
]);

Preset triggers

Choose a preset and configure its parameters — no custom evaluator code required.

age_milestone

Age Milestone

Fires when a subject's calculated age (from a DOB attribute) reaches a configured number of years.

Params: dob_attribute, age

tenure_milestone

Tenure Milestone

Fires when a subject has been a member for a configured number of days, calculated from a pivot joined-date attribute.

Params: joined_date_attribute, days

inactivity

Inactivity

Fires when a subject hasn't been active (checked via a last-active attribute) for more than a configured number of days.

Params: last_active_attribute, days

metric_threshold

Metric Threshold

Fires when a host-provided metric (spend, points, logins…) crosses a threshold. Bind a MetricProviderInterface to enable.

Params: metric_key, operator, value

custom_field_match

Custom Field Match

Fires when any subject attribute satisfies a configured operator/value comparison. Great for dynamic field values and flags.

Params: attribute, operator, value

Actions

When a rule fires, one or more actions execute. Chain as many as you need.

Action Key Description
Set Member Meta set_member_meta Merges a key/value pair into the subject's pivot JSON meta field.
Set Scope Settings set_scope_settings Merges a key/value pair into the tenant/scope settings object.
Notify Scope Admins notify_scope_admins Calls your host-provided notify_scope_admins callback with a payload.
Create Reminder create_reminder Calls your host-provided create_reminder callback with subject + scope.
Dispatch Event dispatch_event Fires a named Laravel event with the subject and rule payload — hook your own listeners.

Other Spiggle packages

Rules Engine pairs perfectly with the rest of the Spiggle ecosystem.