Skip to content

Events and Triggers

Events decide when a workflow starts. The events array registers the workflow with Brezel, while the matching event/* element is the actual entry node in the graph.

Use webhook events for explicit user actions, resource-table buttons, detail-view buttons, or calls from another workflow.

{
"identifier": "createProjectTask",
"type": "webhook",
"module": "projects"
}
{
"name": "createProjectTask",
"type": "event/webhook",
"options": {
"module": "projects",
"public": false,
"refresh_prototype": true
},
"set": {
"project": "default:",
"data": "input:"
}
}

Use a webhook when the action has a clear command name: create, publish, assign, export, approve, reject, regenerate.

Use lifecycle events when behavior must happen automatically after or before a resource change.

Event typeUse for
createInitialize related records after creation.
updateRecalculate derived state after save.
deleteClean up related records after deletion.
beforeCreateValidate or block creation; value edits are not persisted by normal saves.
beforeUpdateValidate or block updates.
beforeSaveValidate or block a save; value edits are not persisted by normal saves.
beforeDeletePrevent deletion or prepare cleanup.

Keep lifecycle workflows narrow. They may run more often than expected because every save operation can trigger them.

Use on_click for layout buttons where the layout component emits the event directly.

{
"identifier": "calculateTaskPreview",
"type": "on_click",
"module": "tasks"
}

Use on_change when a field change should set other fields, load options, or validate a small part of the form.

{
"identifier": "customer",
"type": "select",
"options": {
"references": "customers",
"events": {
"on_change": ["setProjectDefaults"]
}
}
}

on_change workflows usually receive the current prototype, the original resource, and the selector of the changed field. See Data Flow and UI Integration.

Use cron for scheduled maintenance, reminders, status checks, and batch synchronization.

{
"identifier": "sendTaskReminders",
"type": "cron",
"frequency": [[{"schedule": "cron", "parameters": ["0 8 * * 1-5"]}]]
}

Set frequency on the events registration, not only the event element options. Each outer group creates a scheduled job (OR); scheduler calls within a group are chained (AND). For example weekdays plus at 08:30 can be one group; a second cron group adds another time. Names must be Laravel scheduler methods. In tests use dispatch_sync with the cron entry instead of waiting for the scheduler.

Cron workflows should usually be async: true, log their work, and avoid client-only actions such as action/response, action/set, or action/modal.

Use policy events to constrain access dynamically.

{
"identifier": "projectPolicy",
"type": "policy",
"module": "projects",
"roles": ["employee"],
"operations": ["read", "update"],
"allow": ["admin", "manager"],
"roleKey": "slug"
}

Policy workflows typically continue into query/where elements. See Policies and Access.

Use scope or options-style events for reusable query restrictions and dynamic select options. Keep them deterministic and fast because they are often called while the UI is loading.

  • Choose webhook for explicit commands.
  • Choose on_change or on_click for UI-local interactions.
  • Choose lifecycle events for automatic reactions to resource persistence.
  • Choose cron for time-based work.
  • Choose policy for access constraints.
  • Choose action/run from another workflow when orchestration is clearer than exposing a new UI event.

Normal UI/REST saves calculate the persisted values before beforeCreate/beforeUpdate/beforeSave. Changes made by op/set there are not saved. Use these hooks for validation/blocking; use field recipes or a deliberate post-save action/save path to persist values. action/save with triggerEvents reads attributes after beforeSave and differs from the normal save path.

See the generated events for all registered event types, including event/ocrReady (case-sensitive), subscription events, agent_tool and fieldPolicy.