PHPackages                             szana8/laraflow - 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. [Framework](/categories/framework)
4. /
5. szana8/laraflow

ActiveLibrary[Framework](/categories/framework)

szana8/laraflow
===============

Laravel workflow package for Eloquent models.

2.0.1(3y ago)686.4k↓33.3%91MITPHPPHP ^8.0

Since Jul 18Pushed 2y ago4 watchersCompare

[ Source](https://github.com/szana8/laraflow)[ Packagist](https://packagist.org/packages/szana8/laraflow)[ RSS](/packages/szana8-laraflow/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (14)Used By (1)

[![](https://camo.githubusercontent.com/207b513b695fb93be78c10201c8f06ca52d05d6554c3133e19d75b32ca8d7981/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c617261666c6f772e706e673f7468656d653d6461726b267061636b6167654e616d653d737a616e61382532466c617261666c6f77267061747465726e3d617263686974656374267374796c653d7374796c655f32266465736372697074696f6e3d4c617261666c6f772b69732b612b7374616e646172642b776f726b666c6f772b7061636b6167652b666f722b4c61726176656c2b456c6f7175656e742b6f626a656374732e2b596f752b63616e2b646566696e652b796f75722b73746570732532432b7468652b7472616e736974696f6e2b6265747765656e2b7468656d2532432b63616c6c6261636b732532432b616e642b76616c696461746f72732e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)](https://camo.githubusercontent.com/207b513b695fb93be78c10201c8f06ca52d05d6554c3133e19d75b32ca8d7981/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c617261666c6f772e706e673f7468656d653d6461726b267061636b6167654e616d653d737a616e61382532466c617261666c6f77267061747465726e3d617263686974656374267374796c653d7374796c655f32266465736372697074696f6e3d4c617261666c6f772b69732b612b7374616e646172642b776f726b666c6f772b7061636b6167652b666f722b4c61726176656c2b456c6f7175656e742b6f626a656374732e2b596f752b63616e2b646566696e652b796f75722b73746570732532432b7468652b7472616e736974696f6e2b6265747765656e2b7468656d2532432b63616c6c6261636b732532432b616e642b76616c696461746f72732e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)

\# Laravel Workflow Package Laraflow is a standard workflow package for Laravel Eloquent objects. You can define your steps, the transition between them, callbacks, and validators.

[![Total Downloads](https://camo.githubusercontent.com/8703afe9817902212e007d876e09d2e2895a0ecc0cda344f804c695ab38d1199/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f737a616e61382f6c617261666c6f77)](https://packagist.org/packages/szana8/laraflow)[![Latest Stable Version](https://camo.githubusercontent.com/718891768937b1c7f2159b98b21ab0cbd41d3e1f34ac399f583ee58d817251f5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737a616e61382f6c617261666c6f77)](https://packagist.org/packages/szana8/laraflow)[![License](https://camo.githubusercontent.com/5e36e6488bbd518cce00f2b176ec4d0fea835212e4e7df620ae2877526fa7761/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f737a616e61382f6c617261666c6f77)](https://packagist.org/packages/szana8/laraflow)

### Installation (via composer)

[](#installation-via-composer)

You can install the package via composer. The package require Laravel 8 or higher

```
composer require szana8/Laraflow
```

You need to crate the necessary table for the historical data:

```
php artisan migrate
```

After Laravel 5.5 you don't need to manually add the service provider to the config/app.php.

### Configuration file

[](#configuration-file)

After the installation you have to publish a configuration file, which contains a lot of necessary data for the package.

```
php artisan vendor:publish --provider="szana8\Laraflow\LaraflowServiceProvider"

```

#### Configuration array

[](#configuration-array)

You need a configuration array before you use the Laraflow workflow.

Usage
-----

[](#usage)

##### Step 1

[](#step-1)

First you need to add a new column to your Eloquent model table for example called: last\_step/status or whatever you want.

```
 $table->string('status');
```

In your config file *property\_path* attribute has to be the same value than the column name.

##### Step 2

[](#step-2)

You have to add the *Flowable* trait to your Eloquent model to use the workflow.

```
use szana8\Laraflow\Traits\Flowable;

class SampleClass extends Model {

    use Flowable;
```

##### Step 3

[](#step-3)

Than you have to add a function to your eloquent model called *getLaraflowStates()* .
-------------------------------------------------------------------------------------

[](#than-you-have-to-add-a-function-to-your-eloquent-model-called-getlaraflowstates-)

This function has to return the array of the configuration!

The configuration array, when just using 1 state machine in you model must of the form:

```
[
    'default' => [
        //... see published configuration example in config directory.
    ]
];
```

When you have multiple statemachines in your model use the following form:

```
[
    'statemachine_name1' => [ // might also be called 'default' !
        // ...  see published configuration example in config directory
    ],
    'statemachine_name2' => [
        // ...  see published configuration example in config directory
    ],
]
```

##### Step 4

[](#step-4)

If you want to change the status of the Eloquent object you can use the

```
// when using only 1 or at least 'default' named state machine.
$object->transiton($new_status);
// when using only 1 not named state machine.
$statemachineName1 = 'statemachine_name1'
$object->transiton($new_status, $statemachineName1);
$statemachineName2 = 'default'
$object->transiton($new_status, $statemachineName2);
$object->save();
```

method which comes from the *Flowable* trait. The *$new\_status* parameter is the value of the *key* attribute which comes from the *getPossibleTransitions()* function.

History
-------

[](#history)

You can query the history of the record just call the history function in your model like this:

```
/**
* Return historical records.
*
* @return string
*/
public function getFlowHistoryAttribute()
{
return $this->history();
}
```

Events
------

[](#events)

You can listen to the 'global' events which fires in every status changes.

```
LaraflowEvents::PRE_TRANSITION
LaraflowEvents::POST_TRANSITION
LaraflowEvents::CAN_TRANSITION
```

The *PRE\_TRANSITION* fires before the status change, the *POST\_TRANSITION* fires after. The *CAN\_TRANSITION* fires when the package checks the transition is possible from the actual step. You can define callback(s) which will be call from the specified transition.

Validators
----------

[](#validators)

The package comes with a default validator class, which use the Laravel Validator class. You can add validation rules to the transitions, so the package can checks the Eloquent object attributes with the given rules before the transition. If the validation fails throws a LaraflowValidatorException exception with the error message(s) array.

You can define your own validator if you create a class which implements the *LaraflowValidatorInterface*.

```
class TestValidator extends Rule implements LaraflowValidatorInterface
{
    /**
     * Validate the attributes with the given rules.
     *
     * @param array $attributes
     * @param array $rules
     * @return mixed
     */
    public function validate(array $attributes, array $rules)
    {
        if (1 == 2) {
            return true;
        }

        throw LaraflowValidatorException::withMessages(['Validation error']);
    }
}
```

### Commands

[](#commands)

#### Subscriber generation

[](#subscriber-generation)

You can create subscribers for the default Laraflow events with artisan command.

```
foo@bar: php artian laraflow:make subscriber --NameOfTheSubscriber
```

After the run you can find the new subscriber class in the App\\Listener directory. To create a callback class you have to create a class which implements the *LaraflowCallbackInterface* and add the class to the neessary event in the subscriber.

Example:

```
class TestPreCallback implements LaraflowCallbackInterface
{
    public function handle(LaraflowTransitionEvents $event)
    {
        CallbackTest::insert(['message' => json_encode($event->convertToArray())]);
    }
}

class LaraflowEventSubscriber
{
    /**
     * Register the listeners for the subscriber.
     *
     * @param  \Illuminate\Events\Dispatcher  $events
     */
    public function subscribe($events)
    {
        $events->listen(
            LaraflowEvents::PRE_TRANSITION,
            'App\TestPreCallback@handle'
        );
    }
}
```

#### Custom validator generation

[](#custom-validator-generation)

To generate a validator class skeleton for the custom validation you use this command:

```
foo@bar: php artian laraflow:make validator --NameOfTheValidator
```

After the run you can find the new class in the App\\Validators directory.

#### Credits

[](#credits)

This library has been highly inspired by .

#### License

[](#license)

The package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 98.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~157 days

Recently: every ~298 days

Total

12

Last Release

1119d ago

Major Versions

0.16 → 1.02020-01-08

1.0.2 → 2.02022-08-15

PHP version history (2 changes)0.1PHP ^5.6.4 || ^7.0

2.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a4ab48e0d76421d4c39aea0f69e5a8deb734e61d732ad2017e2d2139c1b5ef7?d=identicon)[szana8](/maintainers/szana8)

---

Top Contributors

[![szana8](https://avatars.githubusercontent.com/u/4242050?v=4)](https://github.com/szana8 "szana8 (51 commits)")[![elburgl69](https://avatars.githubusercontent.com/u/5506942?v=4)](https://github.com/elburgl69 "elburgl69 (1 commits)")

---

Tags

hacktoberfesthacktoberfest2022laravelphpstate-machineworkflowworkflow-engine

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/szana8-laraflow/health.svg)

```
[![Health](https://phpackages.com/badges/szana8-laraflow/health.svg)](https://phpackages.com/packages/szana8-laraflow)
```

###  Alternatives

[livewire/livewire

A front-end framework for Laravel.

23.5k75.5M1.8k](/packages/livewire-livewire)[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M529](/packages/laravel-passport)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M106](/packages/laravel-cashier)[laravel/scout

Laravel Scout provides a driver based solution to searching your Eloquent models.

1.7k49.4M479](/packages/laravel-scout)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[laravel/pennant

A simple, lightweight library for managing feature flags.

57311.1M53](/packages/laravel-pennant)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
