Download the PHP package devespresso/system-life-cycle without Composer
On this page you can find all versions of the php package devespresso/system-life-cycle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package system-life-cycle
Laravel Life Cycle System
A Laravel package for managing multi-stage, queue-driven lifecycle workflows on Eloquent models. Define workflows with ordered stages, attach them to any model, and let the system execute, retry, and log every transition automatically.
Requirements
- PHP 8.1+
- Laravel 10 or 11
Installation
Publish the config and migrations:
Configuration
Important: Set
model_id_typebefore running migrations. It controls the column type used formodel_idin thesystem_life_cycle_modelsandsystem_life_cycle_logstables and cannot be changed after migration without a manual schema change.
Core Concepts
Lifecycle
A SystemLifeCycle is the workflow definition. It has a unique code, an active flag, date range, and an ordered set of stages.
Stage
A SystemLifeCycleStage belongs to a lifecycle and holds the sequence (order) and the fully-qualified class name of the service that executes it.
Lifecycle Model
A SystemLifeCycleModel is the per-model record that tracks where a specific Eloquent model is in a specific lifecycle — current stage, status, attempts, payload, and scheduling.
Lifecycle Log
A SystemLifeCycleLog records every execution attempt (success or failure) with the stage, status, payload snapshot, and any error message.
Statuses
| Status | Meaning |
|---|---|
pending |
Waiting to be picked up |
processing |
Claimed by the current run batch |
completed |
All stages finished successfully |
failed |
Exceeded max attempts |
success |
Used in logs to mark a successful execution |
Usage
1. Enable lifecycles on a model
Add the EnableSystemLifeCycles trait to any Eloquent model:
This provides the following methods:
2. Create a stage service
Extend SystemLifeCycleService for each stage in your workflow:
Available helpers in your stage:
| Helper | Description |
|---|---|
$this->model |
The Eloquent model attached to this lifecycle record |
$this->params |
The payload array (persisted across stages) |
$this->systemLifeCycleModel |
The SystemLifeCycleModel record |
$this->setParam(key, value) |
Write a value into the payload |
$this->getParam(key) |
Read a value from the payload |
$this->isRetry() |
Returns true if this is a retry attempt (attempts >= 1) |
$this->setExecutesAt() |
Override to return a Carbon instance for deferred rescheduling |
3. Register the lifecycle
Use the interactive Artisan command to create a lifecycle and its stages:
Or create them programmatically:
4. Attach models to the lifecycle
5. Automatic scheduling
The package automatically registers the following scheduled commands via its service provider:
| Command | Default Frequency |
|---|---|
devespresso:life-cycle:run |
Hourly |
devespresso:life-cycle:logs-clean-up |
Weekly |
devespresso:life-cycle:completed-models-clean-up |
Weekly |
You can customize frequencies or disable auto-scheduling entirely via the schedule config key:
The run command:
- Resets stale
executes_atvalues (older thanstale_after_minutes, default 120) - Assigns the first stage to any records missing one
- Claims all
pendingrecords asprocessingusing a batch ID - Dispatches a
SystemLifeCycleExecuteJobfor each claimed record
Execution window (whereCanBeExecuted scope)
The whereCanBeExecuted scope determines which records are eligible on each tick. A record is eligible when:
- Its lifecycle is active and has started (and not ended)
- If running via cron, the lifecycle has
activate_by_cron = true - Either
executes_atisnull(run immediately) or it falls within the configured window
The window is controlled by schedule.run.window_in_minutes (default 60) and extends in both directions from now(). Boundaries are snapped to startOfMinute() / endOfMinute() so records scheduled at any second within those boundary minutes are included.
When customizing the run frequency, keep all three values in sync:
| Frequency | window_in_minutes |
stale_after_minutes |
|---|---|---|
everyFiveMinutes |
5 | 10 |
everyTenMinutes |
10 | 20 |
hourly (default) |
60 | 120 |
You can also pass custom $startDate / $endDate arguments to the scope to override the config window entirely.
Execution Flow
On exception:
With
max_attempts = 3, a record gets exactly 3 total execution attempts before being marked asfailed.
Stage Payload
The payload column is a JSON object shared across all stages of a lifecycle run. Use setParam and getParam to pass data between stages without extra queries:
Deferred Execution
Return a specific time from setExecutesAt() to control when a rescheduled stage runs:
Re-enrollment
To restart a completed (or failed) lifecycle from the beginning:
This resets the record to stage 1 with status=pending, attempts=0, and clears payload, batch, and executes_at. If the model was never enrolled it creates a fresh record, making it safe to call unconditionally.
Retry Behaviour
When shouldContinueToNextStage() returns false on the first attempt, the stage is rescheduled silently (no log). On subsequent attempts (isRetry() === true) the stage runs regardless, so a model is never permanently stuck waiting.
Custom Model ID Types
If your models use ULIDs, UUIDs, or integer IDs, configure the type before running migrations:
Custom Morph Map
If your application uses morph aliases, enable custom mapping in the config:
Artisan Commands
| Command | Description |
|---|---|
devespresso:life-cycle:create |
Interactively create a lifecycle with stages |
devespresso:life-cycle:run |
Process and dispatch all pending lifecycle records |
devespresso:life-cycle:logs-clean-up |
Delete logs older than log_retention_days |
devespresso:life-cycle:completed-models-clean-up |
Delete completed records older than completed_model_retention_days |
Database Schema
| Table | Description |
|---|---|
system_life_cycles |
Lifecycle definitions |
system_life_cycle_stages |
Ordered stages belonging to a lifecycle |
system_life_cycle_models |
Per-model tracking of current position in a lifecycle |
system_life_cycle_logs |
Immutable execution history (success and failure) |
All tables use a bigIncrements internal primary key (internal_id) and a public ULID identifier (id) for foreign key relationships.
Testing
The package uses Orchestra Testbench with an SQLite in-memory database.
License
MIT
All versions of system-life-cycle with dependencies
illuminate/database Version ^10.0|^11.0
illuminate/support Version ^10.0|^11.0
illuminate/console Version ^10.0|^11.0
illuminate/queue Version ^10.0|^11.0