PHPackages                             ringierimu/state-workflow - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ringierimu/state-workflow

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ringierimu/state-workflow
=========================

Laravel State Workflow provide tools for defining and managing workflows and activities with ease.

5.0.0(2mo ago)3251.1k↓10.3%12MITPHPPHP ^8.3CI passing

Since Jan 7Pushed 2mo ago18 watchersCompare

[ Source](https://github.com/RingierIMU/state-workflow)[ Packagist](https://packagist.org/packages/ringierimu/state-workflow)[ Docs](https://github.com/RingierIMU/state-workflow)[ RSS](/packages/ringierimu-state-workflow/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (20)Versions (19)Used By (0)

Laravel State workflow
======================

[](#laravel-state-workflow)

[![Tests](https://github.com/RingierIMU/state-workflow/actions/workflows/main.yml/badge.svg)](https://github.com/RingierIMU/state-workflow/actions/workflows/main.yml)

**Laravel State workflow** provide tools for defining and managing workflows and activities with ease. It offers an object oriented way to define a process or a life cycle that your object goes through. Each step or stage in the process is called a state. You do also define transitions that describe the action to get from one state to another.

A workflow consist of **state** and **actions** to get from one state to another. These **actions** are called **transitions** which describes how to get from one state to another.

Requirements
------------

[](#requirements)

VersionPHPLaravel5.x8.3+11, 124.x8.1+10, 11Installation
------------

[](#installation)

Requires PHP 8.3+ and Laravel 11+.

```
composer require ringierimu/state-workflow
```

Publish `config/workflow.php` file

```
php artisan vendor:publish  --tag="state-workflow-config"
```

Publish migration

```
php artisan vendor:publish --tag="state-workflow-migration"
```

Run migration

```
php artisan migrate
```

Configuration
-------------

[](#configuration)

1. Open `config/workflow.php` and configure it

```
// this should be your model name in camelcase. eg. PropertyListing::Class => propertyListing
'post' => [
        // class of your domain object
        'class' => \App\Post::class,

        // Register subscriber for this workflow which contains business rules. Uncomment line below to register subscriber
        //'subscriber' => \App\Listeners\UserEventSubscriber::class,

        // property of your object holding the actual state (default is "current_state")
        //'property_path' => 'current_state', //uncomment this line to override default value

        // list of all possible states
        'states' => [
            'new',
            'pending_activation',
            'activated',
            'deleted',
            'blocked'
        ],

        // list of all possible transitions
        'transitions' => [
            'create' => [
                'from' => ['new'],
                'to' => 'pending_activation',
            ],
            'activate' => [
                'from' => ['pending_activation'],
                'to' =>  'activated',
            ],
            'block' => [
                'from' => ['pending_activation', 'activated'],
                'to' => 'blocked'
            ],
            'delete' => [
                'from' => ['pending_activation', 'activated', 'blocked'],
                'to' =>  'deleted',
            ],
        ],
    ],
```

2. Add `HasWorkflowTrait` to your model class to support workflow

```
